ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hii All!!!! does anybody knows how can i cancel the save and the save as commands (https://www.excelbanter.com/excel-programming/352515-hii-all-does-anybody-knows-how-can-i-cancel-save-save-commands.html)

Alon

Hii All!!!! does anybody knows how can i cancel the save and the save as commands
 
Hii All!!!! does anybody knows how can i cancel the 'save' and the
'save as' commands fron an excel workbook? does anybody can write a
code to do it, or maybe a different solution...

Thank you,
Alon


Peter Rooney

Hii All!!!! does anybody knows how can i cancel the save and the s
 
Hi, Alon,

How about these:

Public Sub SaveOn()

Dim CmdBar1 As CommandBar
Dim CmdBar2 As CommandBar

Set CmdBar1 = Excel.CommandBars("Worksheet Menu
Bar").Controls("File").CommandBar

Status = True

For I = 1 To CmdBar1.Controls.Count
CtrlName = CmdBar1.Controls(I).Caption
If CtrlName = "&Save" Or CtrlName = "Save &As..." Then
CmdBar1.Controls(I).Enabled = Status
End If
Next I

Set CmdBar2 = Excel.CommandBars("Standard")
CmdBar2.Controls("Save").Enabled = Status

End Sub

Public Sub SaveOff()

Dim CmdBar1 As CommandBar
Dim CmdBar2 As CommandBar

Set CmdBar1 = Excel.CommandBars("Worksheet Menu
Bar").Controls("File").CommandBar

Status = False

For I = 1 To CmdBar1.Controls.Count
CtrlName = CmdBar1.Controls(I).Caption
If CtrlName = "&Save" Or CtrlName = "Save &As..." Then
CmdBar1.Controls(I).Enabled = Status
End If
Next I

Set CmdBar2 = Excel.CommandBars("Standard")
CmdBar2.Controls("Save").Enabled = Status

End Sub

You could modify them to and move them to "ThisWorkbook" as event macros
too, I should think.

Regards

Pete

"Alon" wrote:

Hii All!!!! does anybody knows how can i cancel the 'save' and the
'save as' commands fron an excel workbook? does anybody can write a
code to do it, or maybe a different solution...

Thank you,
Alon



JMB

Hii All!!!! does anybody knows how can i cancel the save and the s
 
Another variation:

You could paste this into the Thisworkbook module of your workbook through
the VBA editor

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub

If you need to suspend this code in order to save the file yourself, you
could write a macro (and put it in a code module of your workbook - or in a
code module of your Personal macro workbook and assign it a button on your
toolbar or a hotkey) to toggle events on/off (the BeforeSave event would be
suspended while events are off-allowing you to save the file):

Sub ToggleEvents()
With Application
.EnableEvents = Not .EnableEvents
If .EnableEvents Then
.StatusBar = False
Else: .StatusBar = "Events Are Off"
End If
End With

End Sub


"Alon" wrote:

Hii All!!!! does anybody knows how can i cancel the 'save' and the
'save as' commands fron an excel workbook? does anybody can write a
code to do it, or maybe a different solution...

Thank you,
Alon




All times are GMT +1. The time now is 05:32 AM.

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