Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transparent (See through) userforms in Excel

Status
Not open for further replies.

HAGER

Technical User
Jul 30, 2004
4
0
0
US
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
 
Interesting. I am hoping the gurus here can say it can be done, but I believe the userform is "filled".

Gerry
 
This requires windows 2000 or higher. Code in a userform module:

Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (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
 
Ah, I thought there may be an API that might do it. Thanks combo.

Gerry
 

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
 
I'm glad it works.
Forgot to mention that opacity (bytOpacity) can be set within Byte type range, 0 to 255.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top