E
Ed
Hello all,
Using Word 2003. I have a VBA userform which I would like to be
semi-transparent. The form contains the following sub (as well as
declarations and other stuff):
Private Sub UserForm_Initialize()
Dim hwnd As Long
Dim ret As Long
Const Transparency As Integer = 128
hwnd = FindWindow(vbNullString, Me.Caption)
ret = GetWindowLong(hwnd, GWL_EXSTYLE)
ret = ret Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, ret
ret = SetLayeredWindowAttributes(hwnd, 0, Transparency, LWA_ALPHA)
End Sub
The relevant constants are declared in the form module as:
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
The form is instantiated by the following macro:
Sub EditFind()
Dim MyForm As frmFind
Set MyForm = New frmFind
MyForm.Show
Unload MyForm
Set MyForm = Nothing
End Sub
(Originally I tried just using frmFind.Show rather than using the MyForm
variable.)
When I run the macro in the VBA IDE it works, but when I add a toolbar
button in Word to call the macro, the form remains opaque. No errors are
reported.
Any ideas?
Thanks.
Ed
Using Word 2003. I have a VBA userform which I would like to be
semi-transparent. The form contains the following sub (as well as
declarations and other stuff):
Private Sub UserForm_Initialize()
Dim hwnd As Long
Dim ret As Long
Const Transparency As Integer = 128
hwnd = FindWindow(vbNullString, Me.Caption)
ret = GetWindowLong(hwnd, GWL_EXSTYLE)
ret = ret Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, ret
ret = SetLayeredWindowAttributes(hwnd, 0, Transparency, LWA_ALPHA)
End Sub
The relevant constants are declared in the form module as:
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
The form is instantiated by the following macro:
Sub EditFind()
Dim MyForm As frmFind
Set MyForm = New frmFind
MyForm.Show
Unload MyForm
Set MyForm = Nothing
End Sub
(Originally I tried just using frmFind.Show rather than using the MyForm
variable.)
When I run the macro in the VBA IDE it works, but when I add a toolbar
button in Word to call the macro, the form remains opaque. No errors are
reported.
Any ideas?
Thanks.
Ed