+ Reply to Thread
Results 1 to 4 of 4

How to prevent error message during macro

  1. #1
    excelnut1954
    Guest

    How to prevent error message during macro

    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.


  2. #2
    Chip Pearson
    Guest

    Re: How to prevent error message during macro

    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


    "excelnut1954" <[email protected]> wrote in message
    news:[email protected]...
    >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.
    >




  3. #3
    Tom Ogilvy
    Guest

    RE: How to prevent error message during macro

    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.

    --
    Regards,
    Tom Ogilvy


    "excelnut1954" wrote:

    > 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.
    >
    >


  4. #4
    excelnut1954
    Guest

    Re: How to prevent error message during macro

    Thanks guys. Always appreciate the help.
    J.O.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1