Hiding the Title Bar - Specifically the 'X' (exit)

DerekF

Board Regular
Joined
May 28, 2006
Messages
138
There has got to be an easy way to do this. I want to limit the ability to exit the application using the X on the title bar. Instead I want to force ones to use my exit command button.

Any easy ways to do this? I havve searched the web and forums for a while now and haven't come up with anything?

Any help in the right direction would be greatly appreciated...
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
Good afternoon DerekF

You can intercept calls made by the little "X" and flash up a message saying that the user can't close the box that way, but I prefer this way which suppresses the "X" completely.

In a normal module :
Code:
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

Sub HideX(UForm As Object)
Dim Win As Long, WinStyle As Long
If Val(Application.Version) >= 9 Then
Win = FindWindow("ThunderDFrame", UForm.Caption)
Else
Win = FindWindow("ThunderXFrame", UForm.Caption)
End If
WinStyle = GetWindowLong(Win, -16)
SetWindowLong Win, -16, WinStyle And Not &H80000
End Sub

In the userforms code module :
Code:
Private Sub UserForm_Initialize()
HideX UserForm1
End Sub

Just remember to include a "Close" button ... !

HTH

DominicB
 

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
If you use VBA you can intervene in ThisWorkbook's BeforeClose.

You might also consider using a form, with a big exit button that they get used to using.
 

Forum statistics

Threads
1,181,606
Messages
5,930,854
Members
436,764
Latest member
avalladarez

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
Top