Option Explicit
Private Declare PtrSafe Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function GetWindowLong _
Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetLayeredWindowAttributes _
Lib "user32" (ByVal hwnd As LongPtr, ByVal crKey As Long, 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 Sub SetFormOpacity(FormObject As Form, opacity As Long)
Dim currentWindowStyle As Long
currentWindowStyle = GetWindowLong(FormObject.hwnd, GWL_EXSTYLE)
Dim targetWindowStyle As Long
targetWindowStyle = SetWindowLong(FormObject.hwnd, GWL_EXSTYLE, currentWindowStyle Or WS_EX_LAYERED)
SetLayeredWindowAttributes FormObject.hwnd, 0, opacity, LWA_ALPHA
End Sub