How to prevent error message during macro

E

excelnut1954

I have a simple macro to Save-As the workbook. If the workbook already
exists where its suppose to save to, then naturally a dialog box comes
up asking if I want to overwrite the file. If the user clicks NO, then
run-time erorr 1006 comes up
"Method 'Save-As' of object '_ workbook' failed."

Can I add code to just ignore the error and continue on?

Thanks,
J.O.
 
C

Chip Pearson

Use the DisplayAlerts property to suppress warning messages.
E.g.,

Application.DisplayAlerts = False
ThisWorkbook.SaveAs "H:\Book2.xls"
Application.DisplayAlerts = True



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
T

Tom Ogilvy

On Error Resume Next

' current code

On Error goto 0

I would include the minimum number of lines of code between these two
commands as necessary - otherwise you can mask real errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top