Disable X button on excel

P

pano

Is there anyway you can disable the exit button X in excel 2003 as I
only want the users to close and save the workbook thru a button macro
on the worksheet???

Thanks
 
H

Haldun Alay

You can use Workbook_BeforeClose event to force user to close workbook by
pressing a button.

Copy following code to ThisWorkBook code section

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = Not Ok2Close
End Sub

Copy following code to a module

Public Ok2Close As Boolean
Sub CloseMacro()
Ok2Close = True
ThisWorkbook.Close
Ok2Close = False
End Sub

Haldun Alay
 
P

pano

You can use Workbook_BeforeClose event to force user to close workbook by
pressing a button.

Copy following code to ThisWorkBook code section

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = Not Ok2Close
End Sub

Copy following code to a module

Public Ok2Close As Boolean
Sub CloseMacro()
Ok2Close = True
ThisWorkbook.Close
Ok2Close = False
End Sub

Haldun Alay

"pano" <[email protected]>, haber iletisinde sunlari
yazdi:[email protected]...





- Show quoted text -

Hmm Haldun, this sure does stop the user pressing the X button but I
need it to close the workbook which it does but also close excel down

thanks for the help so far
stephen
 
V

vezerid

To close the application insert this line:

Application.Quit

You can enter it before

Ok2Close = False

HTH
Kostis Vezerides
 
P

pano

Toclosethe application insert this line:

Application.Quit

You can enter it before

Ok2Close = False

HTH
Kostis Vezerides





- Show quoted text -

Hmm I have been looking thru the past messages and I found that and
tried it but excel still wont close down am I doing something wrong
here is the code I am using

Public Ok2Close As Boolean
Sub CloseMacro()
Ok2Close = True
ThisWorkbook.Close
ChDir "D:\"
ActiveWorkbook.SaveAs Filename:="D:\DWS.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=True
Application.Quit
Ok2Close = False

End Sub
 
H

Haldun Alay

You are closing file so macro execution stops...

Public Ok2Close As Boolean
Sub CloseMacro()
Ok2Close = True
ChDir "D:\"
ActiveWorkbook.SaveAs Filename:="D:\DWS.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=True
ThisWorkbook.Close
Application.Quit
Ok2Close = False

End Sub
 
G

Guest

Put this in the ThisWorkbook Module

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If CloseMode = vbFormControlMenu Then
MsgBox "Clicking the X button does not work."
Cancel = True
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top