#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Saving file

Hi, I have a template (blank worksheet), I want to prevent the user to
override the template file. The code below will save the template as
different name (taken from cells). I don't know why everytime I press
save button, an error always comes up saying that '....The memory could
not be read' then it will close all the excel application. Any idea ? I
am using excel 2000. The code works fine if I saved it manually with
"file-save as". Thanks

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Application.DisplayAlerts = False
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Temp" & "\" & Range("c10") & Range("c7") & ".xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Dim Msg, Response
Msg = "File was saved as C:\Temp\" & Range("c10") & Range("c7") &
".xls"
Response = MsgBox(Msg, vbExclamation")

Application.DisplayAlerts = True
Application.EnableEvents = True

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Saving file

Try setting Cancel = true

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Application.DisplayAlerts = False
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Temp" & "\" & Range("c10") & Range("c7") & ".xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Dim Msg, Response
Msg = "File was saved as C:\Temp\" & _
Range("c10") & Range("c7") & ".xls"
Response = MsgBox(Msg, vbExclamation")
Cancel = True
Application.DisplayAlerts = True
Application.EnableEvents = True

End Sub

--
Regards,
Tom Ogilvy

"broogle" wrote in message
oups.com...
Hi, I have a template (blank worksheet), I want to prevent the user to
override the template file. The code below will save the template as
different name (taken from cells). I don't know why everytime I press
save button, an error always comes up saying that '....The memory could
not be read' then it will close all the excel application. Any idea ? I
am using excel 2000. The code works fine if I saved it manually with
"file-save as". Thanks

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Application.DisplayAlerts = False
Application.EnableEvents = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Temp" & "\" & Range("c10") & Range("c7") & ".xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Dim Msg, Response
Msg = "File was saved as C:\Temp\" & Range("c10") & Range("c7") &
".xls"
Response = MsgBox(Msg, vbExclamation")

Application.DisplayAlerts = True
Application.EnableEvents = True

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Excel 2007 file in 2003 creates very large file Jon Pearce Excel Discussion (Misc queries) 2 July 16th 09 07:20 PM
Excel should let me sort the file directory when saving a file Beanee70 Excel Discussion (Misc queries) 0 March 14th 06 07:03 AM
How do I stop Excel 2000 from saving file history from file that . Cathy Excel Discussion (Misc queries) 0 March 29th 05 03:27 PM
saving an excel file as an ASCII text file without delimiters Sewellst Excel Programming 4 January 7th 05 01:41 PM
Saving a file(new) using the multiple cell contents as a file name Dave Peterson[_3_] Excel Programming 1 August 1st 03 01:40 PM


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"