Excel

Remove Caption From User Form

Ease of Use

Intermediate

Version tested with

2002, 2003 

Submitted by:

Jacob Hilderbrand

Description:

The macro shows how to remove the top bar from a User Form. 

Discussion:

Sometimes you may want to have a User Form that does not look like a User Form at all. This macro shows how to remove the top bar from the User Form. Note that the user will also be unable to move or close the User Form. 

Code:

instructions for use

			

*** Place this code In a User Form *** Option Explicit Private Sub UserForm_Initialize() Call RemoveCaption(Me) End Sub *** Place this code In a Module *** Option Explicit 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 Sub RemoveCaption(objForm As Object) Dim lStyle As Long Dim hMenu As Long Dim mhWndForm As Long If Val(Application.Version) < 9 Then mhWndForm = FindWindow("ThunderXFrame", objForm.Caption) 'XL97 Else mhWndForm = FindWindow("ThunderDFrame", objForm.Caption) 'XL2000+ End If lStyle = GetWindowLong(mhWndForm, -16) lStyle = lStyle And Not &HC00000 SetWindowLong mhWndForm, -16, lStyle DrawMenuBar mhWndForm End Sub Sub ShowForm() UserForm1.Show False End Sub

How to use:

  1. Open Excel.
  2. Alt + F11 to open the VBE.
  3. Insert UserForm.
  4. Paste the code from above that is designated for the User Form in the User Form code window.
  5. Insert Module.
  6. Paste the code from above that is designated for the Module in the Module code window.
  7. Close the VBE (Alt + Q or press the X in the top right corner).
 

Test the code:

  1. Tools | Macro | Macros...
  2. Select ShowForm and press Run.
 

Sample File:

Example.ZIP 17.23KB 

Approved by mdmackillop


This entry has been viewed 228 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express