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

On Jun 24, 8:55*am, icystorm wrote:
On Jun 24, 8:20*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


Try this. You do not need to restore alerts, etc if you QUIT
Sub archive_and_exitSAS()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
*On Error GoTo nofind
*With ThisWorkbook
* .SaveAs Filename:="\\test\test1" & ".xlsb"
* .SaveAs Filename:="\\test\test2" & _
* *Format(Now, "mmm dd, yyyy-hhmm AM/PM") & ".xlsb"
*End With
Application.Quit


nofind:
'MsgBox "nofind"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Exit Sub
End Sub


Thanks, Don. I appreciate your response and suggestion. I tried the
modification you suggested, but when it executes, Excel still goes
into a mode where it appears to be looking for the path. Consequently,
when it doesn't find the path, it freezes (e.g., the hourglass is
diplayed, and eventually "not responding" appears in the window title
frame).

Do you think that giving it 10 secs or so to find the path and then
going to nofind would work?


Update: I attempted to conditionally qualify if the UNC path exists by
using...

If Dir("//test/", vbDirectory) < "" Then

....but the script (macro) fails on that line. I think the syntax may
be wrong. Instead of Dir and vbDirectory, is the syntax different,
such as Path and vbPath? I looked and could not find any references
other than Dir and vbDirectory. Those may only refer to the mapped
drive. I need to verify if the specific UNC path exists before
proceeding, otherwise, my macro hangs while it is presumably looking
for the UNC path and not finding it.

Thanks!