ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Disable X button on excel (https://www.excelbanter.com/excel-worksheet-functions/136312-disable-x-button-excel.html)

pano

Disable X button on excel
 
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


Haldun Alay

Disable X button on excel
 
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" , haber iletisinde sunlari
roups.com...
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




pano

Disable X button on excel
 
On Mar 27, 5:08 pm, "Haldun Alay" wrote:
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" , haber iletisinde sunlari
roups.com...



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- Hide quoted text -


- 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


vezerid

Disable X button on excel
 
To close the application insert this line:

Application.Quit

You can enter it before

Ok2Close = False

HTH
Kostis Vezerides

On Mar 27, 2:45 pm, "pano" wrote:
On Mar 27, 5:08 pm, "Haldun Alay" wrote:



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" , haber iletisinde sunlari
roups.com...


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- Hide quoted text -


- 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




pano

Disable X button on excel
 
On Mar 27, 9:54 pm, "vezerid" wrote:
Toclosethe application insert this line:

Application.Quit

You can enter it before

Ok2Close = False

HTH
Kostis Vezerides

On Mar 27, 2:45 pm, "pano" wrote:



On Mar 27, 5:08 pm, "Haldun Alay" wrote:


You can use Workbook_BeforeClose event to force user tocloseworkbook 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" , haber iletisinde sunlari
roups.com...


Is there anyway you can disable the exit button X inexcel2003 as I
only want the users tocloseand save the workbook thru a button macro
on the worksheet???


Thanks- Hide quoted text -


- Show quoted text -


Hmm Haldun, this sure does stop the user pressing the X button but I
need it toclosethe workbook which it does but alsocloseexceldown


thanks for the help so far
stephen- Hide quoted text -


- 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


Haldun Alay

Disable X button on excel
 
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


"pano" , haber iletisinde sunlari
roups.com...
On Mar 27, 9:54 pm, "vezerid" wrote:
Toclosethe application insert this line:

Application.Quit

You can enter it before

Ok2Close = False

HTH
Kostis Vezerides

On Mar 27, 2:45 pm, "pano" wrote:



On Mar 27, 5:08 pm, "Haldun Alay" wrote:


You can use Workbook_BeforeClose event to force user tocloseworkbook
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" , haber iletisinde sunlari
roups.com...


Is there anyway you can disable the exit button X inexcel2003 as I
only want the users tocloseand save the workbook thru a button
macro
on the worksheet???


Thanks- Hide quoted text -


- Show quoted text -


Hmm Haldun, this sure does stop the user pressing the X button but I
need it toclosethe workbook which it does but alsocloseexceldown


thanks for the help so far
stephen- Hide quoted text -


- 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




Mike

Disable X button on excel
 
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

"pano" wrote:

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




All times are GMT +1. The time now is 06:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com