Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default How To Exit Macro Without Debug Prompting

I am using a macro to save an XLS however if the file already exists you are
promted, as normal, if you want to replace the file or not (Yes or No). If I
choose "No" I just want to exit the macro however I am prompted with
"Continue, End or Debug".

How can I just exit from this macro gracefully? Turning "Display Alerts"
off is not an option, although it works. My code follows...

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default How To Exit Macro Without Debug Prompting

The problem is not with the Display Alerts; You have syntax errors in the
line of code.

You need the last backslash between the path and filename and remove the
parenthesis.

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel\" & SaveAsFile & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


If you want to save over an existing file and don't want the warning alert
then include the following line before the above code.
Application.DisplayAlerts = False

--
Regards,

OssieMac


"GEdwards" wrote:

I am using a macro to save an XLS however if the file already exists you are
promted, as normal, if you want to replace the file or not (Yes or No). If I
choose "No" I just want to exit the macro however I am prompted with
"Continue, End or Debug".

How can I just exit from this macro gracefully? Turning "Display Alerts"
off is not an option, although it works. My code follows...

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default How To Exit Macro Without Debug Prompting

Since you said that turning display alerts off is not an option. And if you
want it to be completely "quiet", delete my MsgBox line of code.

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...
On Error Resume Next
ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
If Err < 0 Then
'probably clicked [NO] in response to overwrite warning
'so just ignore the error and press on
MsgBox "Error: " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & _
"Encountered. File NOT saved.", vbOKOnly + vbCritical, "Error
Encountered"
Err.Clear
End If
On Error GoTo 0 ' clear error trapping
End If
End Sub


"GEdwards" wrote:

I am using a macro to save an XLS however if the file already exists you are
promted, as normal, if you want to replace the file or not (Yes or No). If I
choose "No" I just want to exit the macro however I am prompted with
"Continue, End or Debug".

How can I just exit from this macro gracefully? Turning "Display Alerts"
off is not an option, although it works. My code follows...

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default How To Exit Macro Without Debug Prompting

Many thanks for your assistance. This is the code I needed and it works great.

"JLatham" wrote:

Since you said that turning display alerts off is not an option. And if you
want it to be completely "quiet", delete my MsgBox line of code.

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...
On Error Resume Next
ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
If Err < 0 Then
'probably clicked [NO] in response to overwrite warning
'so just ignore the error and press on
MsgBox "Error: " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & _
"Encountered. File NOT saved.", vbOKOnly + vbCritical, "Error
Encountered"
Err.Clear
End If
On Error GoTo 0 ' clear error trapping
End If
End Sub


"GEdwards" wrote:

I am using a macro to save an XLS however if the file already exists you are
promted, as normal, if you want to replace the file or not (Yes or No). If I
choose "No" I just want to exit the macro however I am prompted with
"Continue, End or Debug".

How can I just exit from this macro gracefully? Turning "Display Alerts"
off is not an option, although it works. My code follows...

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default How To Exit Macro Without Debug Prompting

OssieMac,
Thanks for your review of my code. My save was coded correctly as I did
want the value "SaveAsFile" as part of the XLS filename. For example;

E:\Fun With Excel\Playing With Excel (Macro Fun).xls

The problem was if I clicked [NO] or [Cancel] in response to the overwrite
warning I received the error, although not really an error.

See the example from JLatham.

Thanks again.

"OssieMac" wrote:

The problem is not with the Display Alerts; You have syntax errors in the
line of code.

You need the last backslash between the path and filename and remove the
parenthesis.

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel\" & SaveAsFile & ".xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False


If you want to save over an existing file and don't want the warning alert
then include the following line before the above code.
Application.DisplayAlerts = False

--
Regards,

OssieMac


"GEdwards" wrote:

I am using a macro to save an XLS however if the file already exists you are
promted, as normal, if you want to replace the file or not (Yes or No). If I
choose "No" I just want to exit the macro however I am prompted with
"Continue, End or Debug".

How can I just exit from this macro gracefully? Turning "Display Alerts"
off is not an option, although it works. My code follows...

Sub SaveXLS()
If Range("A1").Value = "" Then
MsgBox ("Cell A1 must have an entry.")
Else
SaveAsFile = ThisWorkbook.Worksheets("Sheet1").Range("A1")

ChDir "E:\Fun With Excel"

'It is at this next process I have my issue...

ActiveWorkbook.SaveAs Filename:= _
"E:\Fun With Excel\Playing With Excel (" & SaveAsFile & ").xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

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
Restrict Prompting for Macro Security Rob Excel Programming 6 August 14th 08 10:44 PM
Excel Macro Prompting crusse04 Excel Programming 2 June 12th 08 09:11 PM
Macro Examples for prompting info Patches Excel Programming 1 May 9th 07 07:25 PM
Prompting 'Save As' in an Excel Macro Glenn Gooding Excel Programming 1 December 2nd 04 09:49 AM
Prompting a macro to run on change of cell content NuclearWookiee Excel Programming 11 April 15th 04 06:37 PM


All times are GMT +1. The time now is 08:47 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"