This code makes an userform semitransparently. Place the following controls on an Userform.
CommandButton1
ScrollBar1
Label1
Please note, the userform will be invisible when you move scroll bar to 100%. It means you cannot control that userform anymore.
Private Declare Function GetActiveWindow Lib "USER32" () As Long
Private Declare Function SetWindowLong Lib "USER32" _
Alias "SetWindowLongA" ( _
ByVal hWnd As Long, ByVal lngWinIdx As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "USER32" _
Alias "GetWindowLongA" ( _
ByVal hWnd As Long, ByVal lngWinIdx As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "USER32" ( _
ByVal hWnd As Long, ByVal crKey As Integer, _
ByVal bAlpha As Integer, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = &HFFEC
Dim hWnd As Long
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub ScrollBar1_Change()
Call Semitransparent(Me.ScrollBar1.Value)
End Sub
Private Sub UserForm_Activate()
Me.ScrollBar1.Value = 50
End Sub
Private Sub Semitransparent(ByVal intLevel As Integer)
Dim lngWinIdx As Long
hWnd = GetActiveWindow
lngWinIdx = GetWindowLong(hWnd, GWL_EXSTYLE)
SetWindowLong hWnd, GWL_EXSTYLE, lngWinIdx Or WS_EX_LAYERED
SetLayeredWindowAttributes hWnd, 0, (255 * intLevel) / 100, LWA_ALPHA
Label1.Caption = "Semitransparent level is ..." & (100 - intLevel) & "%"
End Sub