Put all this in the Userform code module at the top: (make sure you have a
way to close the userform - such as the code in the commandbutton).
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 DrawMenuBar _
Lib "user32" _
( _
ByVal hWnd As Long _
) _
As Long
Private Function fncHasUserformCaption _
( _
bState As Boolean _
)
'change the style of the Userform window to have a
'caption or not to
'declarations of variables
Dim Userform_hWnd As Long
Dim Userform_Style As Long
'required API consatants
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000
'get a handle to the userform window
Userform_hWnd = FindWindow _
( _
lpClassName:=IIf(Val(Application.Version) > 8, _
"ThunderDFrame", _
"ThunderXFrame"), _
lpWindowName:=Me.Caption _
)
'get the current style of the window
Userform_Style = GetWindowLong _
( _
hWnd:=Userform_hWnd, _
nIndex:=GWL_STYLE _
)
'deside whether to redraw the form with a caption or without
'based on the bState parameter
If bState = True Then
Userform_Style = Userform_Style Or WS_CAPTION
Else
Userform_Style = Userform_Style And Not WS_CAPTION
End If
'set the new style to the window
Call SetWindowLong _
( _
hWnd:=Userform_hWnd, _
nIndex:=GWL_STYLE, _
dwNewLong:=Userform_Style _
)
'redraw the window using the new style
Call DrawMenuBar _
( _
hWnd:=Userform_hWnd _
)
End Function
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
fncHasUserformCaption False
End Sub