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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,222,310
Messages
6,165,259
Members
451,949
Latest member
bovacik

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