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!

Remove the title bar from a userform

VBA How To

Remove the title bar from a userform

by  taupirho  Posted    (Edited  )
To remove the title bar from a vba userform we need to use the win API so please make sure you're comfortable with this before continuing.

First create a new form, userform2 say, and put the following in the general declaration section:

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 Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const WS_CAPTION As Long = &HC00000 'Style to add a titlebar


Next in the initialize section all you need is the following code:

hwndform = FindWindow("ThunderXframe", UserForm2.Caption)

istyle = GetWindowLong(hwndform, GWL_STYLE)
istyle = istyle And Not WS_CAPTION
X = SetWindowLong(hwndform, GWL_STYLE, istyle)
DrawMenuBar hwndform

'ThunderXframe' in the FindWindow call above refers to the userforms class code name that microsoft developers had for EXCEL 97. For EXCEL 2000 applications and up you should use 'ThunderDframe'. No doubt future versions of EXCEL will have their own codes too, look 'em up on google if you need them.


Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top