Results 1 to 8 of 8

Thread: Remove UserForm's TitleBar And Frame

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13

    Remove UserForm's TitleBar And Frame

    Every now and again, someone on a forum requests to have the title bar removed from their UserForm. The reason may simply be to remove the Exit Button (the red X in the upper right corner) or to get rid of the windows framework which is deemed "ugly" given the UserForm's design. Actually, with some simple Windows API function calls (sorry Mac users, but this code will not work for you), removing the title bar and windows border is quite easy to do. Of course, without a title bar, your user will not be able to move the UserForm around the screen. Again, the Windows API functions come to the rescue... setting up the ability to move a UserForm having no title bar is also quite easy to do. Simply put this code into your UserForm's code window and you are done.

    Code:
    '**** Start of API Calls To Remove The UserForm's Title Bar ****
    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
    '**** End of API Calls To Remove The UserForm's Title Bar ****
    
    '**** Start of API Calls To Allow User To Slide UserForm Around The Screen ****
    Private Declare Function SendMessage Lib "user32" _
                    Alias "SendMessageA" _
                   (ByVal hWnd As Long, _
                    ByVal wMsg As Long, _
                    ByVal wParam As Long, _
                    lParam As Any) As Long
     
    
    Private Declare Function ReleaseCapture Lib "user32" () As Long
     
    
    Private Const WM_NCLBUTTONDOWN = &HA1
    Private Const HTCAPTION = 2
    '**** End of API Calls To Allow User To Slide UserForm Around The Screen ****
    
    Dim hWndForm As Long
    
    Private Sub UserForm_Initialize()
       Dim Style As Long, Menu As Long
       hWndForm = FindWindow("ThunderDFrame", Me.Caption)
       Style = GetWindowLong(hWndForm, &HFFF0)
       Style = Style And Not &HC00000
       SetWindowLong hWndForm, &HFFF0, Style
       DrawMenuBar hWndForm
    End Sub
    
    Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
      If Button = xlPrimaryButton And Shift = 1 Then
        Call ReleaseCapture
        Call SendMessage(hWndForm, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&)
      End If
    End Sub
    Note 1
    ------------
    Important -- make sure to provide an "Exit" button for closing the UserForm down (remember, there will be no Exit Button on the Window frame for the users to use to do this, so you have to provide one for them).

    Note 2
    -----------
    To slide the UserForm around, hold the Shift Key down, left click a blank area of the UserForm (NOT a control on the UserForm) and with the left mouse button still depressed, slide the mouse around the screen until you have it located where you want. I chose to use the Shift Key as part of this functionality for its mnemonic value (Shift Key = Shift UserForm Around), but this can be changed as needed in the If..Then statement inside the UserForm_MouseDown event procedure.
    Last edited by Rick Rothstein; 08-29-2012 at 10:33 PM.

Similar Threads

  1. Remove Special Characters From Text Or Remove Numbers From Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 05-31-2013, 04:43 PM
  2. One userform and 60 Combo Boxes
    By k0st4din in forum Excel Help
    Replies: 11
    Last Post: 04-25-2013, 09:55 AM
  3. Multiple graph in userform
    By Tony in forum Excel Help
    Replies: 3
    Last Post: 10-20-2012, 09:32 AM
  4. Replies: 3
    Last Post: 12-07-2011, 09:59 PM
  5. Userform With DataGrid or FlexGrid
    By Rasm in forum Excel Help
    Replies: 5
    Last Post: 04-09-2011, 09:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •