Is it possible to remove the header on a userform?
Printable View
Is it possible to remove the header on a userform?
yes, try changing the border style to see if you can get what you want that way
There is no property of the userform to remove the titlebar as we can do it in VB6 (Which is also known as borderless form). To achieve what you want we have to use few API Calls. Create a userform and also create one commandbutton on it.
Paste this code in the Userform area...
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 DrawMenuBar Lib "User32" ( _
ByVal hwnd As Long) As Long
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Call RemTitleBar(Me)
End Sub
'~~> Removes Titlebar
Sub RemTitleBar(objForm As Object)
Dim lStyle As Long, hMenu As Long, mhWndForm As Long
If Val(Application.Version) < 9 Then
'~~> For Excel 97
mhWndForm = FindWindow("ThunderXFrame", objForm.Caption)
Else
'~~> For Excel 2000 onwards
mhWndForm = FindWindow("ThunderDFrame", objForm.Caption)
End If
lStyle = GetWindowLong(mhWndForm, -16)
lStyle = lStyle And Not &HC00000
SetWindowLong mhWndForm, -16, lStyle
'~~> Draw the Final userform
DrawMenuBar mhWndForm
End Sub
Sub ShowForm()
UserForm1.Show False
End Sub
Koolsid as ever you are a genius! Many thanks indeed!