[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]