Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Simple and Bulletproof Save/SaveAs Procedure

I've been trying to emulate the Save button (or CTRL-S) in as simple and
bulletproof a manner as possible. This is the best I could do.

Using ActiveWorkbook.SaveAs required using Application.DisplayAlerts = False
because the SaveAs method produces its own "Do you want to replace the
existing file? Yes, No, Cancel" message box if a file with the same name
already exists. Without DisplayAlerts = False, the user would get TWO
"Replace?" message boxes, and pressing "No" or "Cancel" on the message box
produced by ActiveWorkbook.SaveAs results in a run-time error.

In most cases "SendKeys "^s", True" is an elegant solution, but I was
wondering if anyone could improve upon this code.

Dim oSaveName As Variant
Dim oReturnValue As Long

If MsgBox("Save?", vbYesNo) = vbYes Then
If ActiveWorkbook.Path = "" Then
Do
oSaveName = Application.GetSaveAsFilename(, "Microsoft Office
Excel Workbook (*.xls), *.xls")
If TypeName(oSaveName) = "Boolean" Then Exit Do
If Dir(oSaveName) < "" Then
oReturnValue = MsgBox("Replace?", vbYesNo)
End If
Loop Until oReturnValue = vbYes
If TypeName(oSaveName) < "Boolean" Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs (oSaveName)
Application.DisplayAlerts = True
End If
Else
ActiveWorkbook.Save
End If
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,574
Default Simple and Bulletproof Save/SaveAs Procedure

If you're just interested in a simple and bulletproof save (not saveas)
function, you can just add the add-in autosave. Tools--Add-ins.

If you're on a network you may need to get your it department to install the
add-ins on your excel installation.

"Lazzaroni" wrote:

I've been trying to emulate the Save button (or CTRL-S) in as simple and
bulletproof a manner as possible. This is the best I could do.

Using ActiveWorkbook.SaveAs required using Application.DisplayAlerts = False
because the SaveAs method produces its own "Do you want to replace the
existing file? Yes, No, Cancel" message box if a file with the same name
already exists. Without DisplayAlerts = False, the user would get TWO
"Replace?" message boxes, and pressing "No" or "Cancel" on the message box
produced by ActiveWorkbook.SaveAs results in a run-time error.

In most cases "SendKeys "^s", True" is an elegant solution, but I was
wondering if anyone could improve upon this code.

Dim oSaveName As Variant
Dim oReturnValue As Long

If MsgBox("Save?", vbYesNo) = vbYes Then
If ActiveWorkbook.Path = "" Then
Do
oSaveName = Application.GetSaveAsFilename(, "Microsoft Office
Excel Workbook (*.xls), *.xls")
If TypeName(oSaveName) = "Boolean" Then Exit Do
If Dir(oSaveName) < "" Then
oReturnValue = MsgBox("Replace?", vbYesNo)
End If
Loop Until oReturnValue = vbYes
If TypeName(oSaveName) < "Boolean" Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs (oSaveName)
Application.DisplayAlerts = True
End If
Else
ActiveWorkbook.Save
End If
End If

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
Is there a simple procedure to hide rows if a condition is met fishingengineer Excel Discussion (Misc queries) 1 April 13th 07 08:26 PM
Trim function as a procedure - a simple example [email protected] Excel Programming 0 June 26th 06 05:26 PM
Excel crashes on simple procedure Daves_Solutions[_2_] Excel Programming 6 June 14th 06 06:05 AM
Is there a simple procedure to set my macros in Excel 2003 to be . shelley New Users to Excel 1 April 22nd 05 10:04 PM
Help 'splain unusual behavior in simple procedure tod Excel Programming 0 January 13th 04 11:13 PM


All times are GMT +1. The time now is 01:00 AM.

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

About Us

"It's about Microsoft Excel"