Transparent (See through) userforms in Excel
Transparent (See through) userforms in Excel
(OP)
Question for you experts - Is there a way to take the userform I created for excel in Microsoft visual basic and make it transparent(See through)over my excel application?
Currently the form must be moved or minimized to get it out of the way.
Thanks in advance,
Tracey
Currently the form must be moved or minimized to get it out of the way.
Thanks in advance,
Tracey
RE: Transparent (See through) userforms in Excel
Gerry
RE: Transparent (See through) userforms in Excel
CODE
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hWnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2&
Public hWnd As Long
Private Sub UserForm_Initialize()
Dim bytOpacity As Byte
bytOpacity = 192 ' variable keeping opacity setting
hWnd = FindWindow("ThunderDFrame", Me.Caption)
Call SetWindowLong(Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
Call SetLayeredWindowAttributes(Me.hWnd, 0, bytOpacity, LWA_ALPHA)
End Sub
combo
RE: Transparent (See through) userforms in Excel
Gerry
RE: Transparent (See through) userforms in Excel
Thanks combo the code worked flawlessly.
The only snag I had was when I forgot to put the declarations up in the Option Explicit portion of the userform module. Woops!!!
Thanks again,
Tracey
RE: Transparent (See through) userforms in Excel
Forgot to mention that opacity (bytOpacity) can be set within Byte type range, 0 to 255.
combo