View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
icystorm icystorm is offline
external usenet poster
 
Posts: 20
Default save and exit macro

On Jun 25, 7:26*am, Don Guillett wrote:
On Sunday, June 24, 2012 7:39:43 AM UTC-5, icystorm wrote:
Greetings:


I wrote a macro (below) to save a workbook to two files and exit. If
the paths are not available, the workbook should not be saved and
Excel should simply quit.


I think I may be misuing On Error Resume Next below, because the fact
that the script is not finding the path is not causing an error. Any
advice?


Again, if the path is not found, I want Excel to simply exit (after
restoring screenupdating and displayalerts). All changes are intended
to be discarded if the script is unable to locate and save to the
identified path. Thanks!


---


Sub archive_and_exit()


Application.ScreenUpdating = False
Application.DisplayAlerts = False


* * On Error Resume Next
* * With ThisWorkbook
* * * * .SaveAs Filename:="\\test\test1" & ".xlsb"
* * * * .SaveAs Filename:="\\test\test2" & Format(Now, "mmm dd, yyyy -
hhmm AM/PM") & ".xlsb"
* * End With


* * * *Application.Quit
* * * *ActiveWorkbook.Close False


Application.DisplayAlerts = True
Application.ScreenUpdating = True


End Sub


Look here for possible answershttp://tinyurl.com/79vrwqq


Thanks again for your help, Don. I appreciate your assistance. I had
looked extensively though many of those options you suggested before
posting here, but without success. I began looking for some ancillary
and similar problems today and found some hints that helped. Using
several similar solutions, I was able to craft the following, which
works perfectly with a UNC path. I'm not sure if it is as efficient as
it could or should be, but it works perfectly for both cases of when
the UNC path is available and is not available.

If anyone has any recommendations to tidy this up, please share...
Otherwise, I'm happy with the way it is.

Sub archive_and_exit()

On Error Resume Next
stringvariable = ""
stringvariable = Dir("\\your\UNC\path\here\", vbDirectory)
If Err.Number < 0 Then
MsgBox "Cannot archive. Server UNC Path \\your\UNC\path\here\ is not
available."
Err.Clear
End If
If stringvariable < "" Then

With ThisWorkbook
.SaveAs Filename:="\\your\UNC\path\here\filename.xxx"
End With
Application.Quit

End If
End Sub