Remove the Title Bar from a UserForm

Add to Favorites
Author: | Edits: don

Remove the Title Bar and border from a form, including the red X, or close button.

This creates a clean UserForm interface and is great for things like splash pages or just giving your forms a cleaner and more streamlined appearance.

c505a1ac65411e09709c4c3ab9ab81e6.jpg

Sections:

Remove Title Bar from UserForm

Notes

Remove Title Bar from UserForm

To remove the title bar and border, we need to add VBA code into a regular module and then call that code from the UserForm_Initialize event, which is what runs when a form is opened.

Module Code

The below code goes into a regular module in the VBA window. (Alt + F11 to get to the VBA window and then Insert > Module.)

Option Explicit

#If VBA7 Then
    Public Declare PtrSafe Function FindWindow Lib "user32" _
                Alias "FindWindowA" _
               (ByVal lpClassName As String, _
                ByVal lpWindowName As String) As Long


    Public Declare PtrSafe Function GetWindowLong Lib "user32" _
                Alias "GetWindowLongA" _
               (ByVal hWnd As Long, _
                ByVal nIndex As Long) As Long


    Public Declare PtrSafe Function SetWindowLong Lib "user32" _
                Alias "SetWindowLongA" _
               (ByVal hWnd As Long, _
                ByVal nIndex As Long, _
                ByVal dwNewLong As Long) As Long


    Public Declare PtrSafe Function DrawMenuBar Lib "user32" _
               (ByVal hWnd As Long) As Long
#Else
    Public Declare Function FindWindow Lib "user32" _
                Alias "FindWindowA" _
               (ByVal lpClassName As String, _
                ByVal lpWindowName As String) As Long


    Public Declare Function GetWindowLong Lib "user32" _
                Alias "GetWindowLongA" _
               (ByVal hWnd As Long, _
                ByVal nIndex As Long) As Long


    Public Declare Function SetWindowLong Lib "user32" _
                Alias "SetWindowLongA" _
               (ByVal hWnd As Long, _
                ByVal nIndex As Long, _
                ByVal dwNewLong As Long) As Long


    Public Declare Function DrawMenuBar Lib "user32" _
               (ByVal hWnd As Long) As Long
#End If

Note: this code must go at the very top of the module before any other code!

The next section of code can be placed anywhere within the module.

Sub HideBar(frm As Object)

Dim Style As Long, Menu As Long, hWndForm As Long
hWndForm = FindWindow("ThunderDFrame", frm.Caption)
Style = GetWindowLong(hWndForm, &HFFF0)
Style = Style And Not &HC00000
SetWindowLong hWndForm, &HFFF0, Style
DrawMenuBar hWndForm

End Sub

UserForm Code

Code must also be placed within the UserForm itself in order to work.

All you need to do is call HideBar and pass it a reference to the form.

HideBar Me

This piece of code should be placed inside the UserForm_Initialize event. This event will usually have other code inside of it, but the most basic version of the event for this example could look like this:

Private Sub UserForm_Initialize()

'Remove Border and Title Bar
HideBar Me

End Sub

To learn more about the Initialize event and events in general, view our tutoral on UserForm Events.

Notes

Removing the title bar removes the default close button on the form; as such, you should place a button somehwere on the form that will allow the user to close it.

This also removes the ability to move the form around the window with your mouse; as such, you should think about this before implementing this code or you should use additional code that allows the user to move the form by clicking on it and dragging it without a title bar.

This code works great with splash screens in Excel but you can use it any time you want your form to have a more streamlined look.

Don't forget to download the sample file to see this example in Excel.

Question? Ask it in our Excel Forum


Downloadable Files: Excel File

Similar Content on TeachExcel
Creating a Splash Screen in Excel
Tutorial: Create a pop-up window, splash screen, that appears when Excel starts. This allows you to ...
Getting Data from a UserForm
Tutorial: How to get data from a UserForm in Excel, including from: text inputs (TextBox), list boxe...
Select Ranges in the Worksheet from a UserForm
Tutorial: Select a range in Excel from a UserForm and have that range input into the form so that yo...
Remove All Data Validation from a Cell in Excel
Macro: Remove all data validation from a cell in Excel with this free Excel macro. This is a grea...
Formula to Delete the First or Last Word from a Cell in Excel
Tutorial: Excel formula to delete the first or last word from a cell. You can copy and paste the for...
Sum the Visible Rows from a Filtered List in Excel
Tutorial: How to SUM only the visible rows from a filtered data set in Excel. To do this, we will us...
Tutorial Details
Downloadable Files: Excel File
Similar Content
Creating a Splash Screen in Excel
Tutorial: Create a pop-up window, splash screen, that appears when Excel starts. This allows you to ...
Getting Data from a UserForm
Tutorial: How to get data from a UserForm in Excel, including from: text inputs (TextBox), list boxe...
Select Ranges in the Worksheet from a UserForm
Tutorial: Select a range in Excel from a UserForm and have that range input into the form so that yo...
Excel Forum