Charlie2618
04-11-2004, 05:39 PM
Hello, Everyone,
I have one file which I don't want to somebody to save anything to it. So, I would like to hide the save item in the standard menu. Customer can use the save as to save the file in other file name. Would somebody know how to do it? Thank you very much!
Have a nice day!
Charlie
italkid
04-11-2004, 10:24 PM
Access, Word, Powerpoint, Excel ???
For instance in Excel you could make use of the Before_Save event to
disable the save option with one single line of code :
Cancel = True
:)
Charlie2618
04-12-2004, 07:59 AM
italkid,
Thanks for your help. I use this code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
SaveAsUI = True
Cancel = True
End Sub
I hope that it can disable save button and prompt SaveAsUI. However, it doesn't work. Do you know why?
Thank you very much!
Charlie
Charlie2618
04-12-2004, 10:20 AM
Hello, Everyone:
I tried to use following programming to disable save and prompt SaveAs dialog when save button is hit. I don't know why SaveAsUI dones't function as I think? Thank you very much!
Charlie
Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
SaveAsUI = True
Cancel = True
End Sub
XL-Dennis
04-12-2004, 11:38 AM
SaveAsUI is usually used in conjunction with Application.GetSaveAsFilename which can let us control which filename the users want to save it under.
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim vaFileName As Variant
SaveAsUI = True
vaFileName = Application.GetSaveAsFilename(InitialFilename:="", _
FileFilter:="Excel Filer (*.xls), *.xls", Title:="Save as...")
If vaFileName = False Then
Cancel = True
Exit Sub
End If
'Code continue...
End Sub
If You just want to prevent the users from saving the workbook then You should only use Cancel and setting it to True.
Charlie2618
04-12-2004, 12:51 PM
Thanks, Dennis. It solves my problem.
Charlie
italkid
04-12-2004, 01:43 PM
Another approach.
Disable all of the "Save" buttons exept "Save As" :
'in the workbook_open event
Dim Butt As CommandBarButton
For Each Butt In Application.CommandBars.FindControls(ID:=3)
Butt.Enabled = False
Next Butt
'and of course the opposite in the workbook_beforeclose event
If you want to use this for a single workbook it would be better to use the
window- activate and deactivate event... :)