Without Window bar

Rangsa

New Member
Joined
Oct 30, 2018
Messages
1
Dear Friends,
Is it possible hide window bar and close button from a userform in excel vba?
Please reply me!
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
This works on my different computers but might not work with some versions, Apple, etc. I start all my userform with this

Code:
[COLOR=#008000]'Hide a UserForm's Close Button[/COLOR]
[COLOR=#008000]'Works On 64 Bit. For other versions delete the word "PtrSafe" 3 times in declarations below[/COLOR]
[COLOR=#008000]'Find the userform's Window[/COLOR]
Private Declare PtrSafe Function FindWindow Lib "user32" _
        Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
[COLOR=#008000]'Get the current window style[/COLOR]
Private Declare PtrSafe Function GetWindowLong Lib "user32" _
        Alias "GetWindowLongA" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long) As Long
[COLOR=#008000]'Set the new window style[/COLOR]
Private Declare PtrSafe Function SetWindowLong Lib "user32" _
        Alias "SetWindowLongA" ( _
        ByVal hWnd As Long, _
        ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long
Const GWL_STYLE = -16
Const WS_SYSMENU = &H80000

[COLOR=#0000cd]Private Sub UserForm_Activate()[/COLOR]
[COLOR=#008000]'Hide the close button[/COLOR]
  Dim hWnd As Long, lStyle As Long
[COLOR=#008000]   'Which type of userform[/COLOR]
   If Val(Application.Version) >= 9 Then
      hWnd = FindWindow("ThunderDFrame", Me.Caption)
   Else
      hWnd = FindWindow("ThunderXFrame", Me.Caption)
   End If
[COLOR=#008000]   'Get the current window style and turn off the Close button[/COLOR]
   lStyle = GetWindowLong(hWnd, GWL_STYLE)
   SetWindowLong hWnd, GWL_STYLE, (lStyle And Not WS_SYSMENU)
[COLOR=#008000] 'Put userform in middle of excel window[/COLOR]
       Me.StartUpPosition = 0
       Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
       Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)
[COLOR=#ff0000]
Your code[/COLOR]

[COLOR=#0000cd]End sub[/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,091
Messages
6,123,062
Members
449,089
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top