+ Reply to Thread
Results 1 to 3 of 3

How to avoid an error dialog

  1. #1
    justaguyfromky
    Guest

    How to avoid an error dialog

    I have a simple code to save a couple of pages of paperwork to a file to be
    emailed to corporate nightly, It works fine. The problem that I am having is
    that if someone runs this script and chooses to cancel the process at any
    point I get a run time error 1004: Method 'SaveAs' of object '_Workbook'
    failed. Then offers the Debug button for VB editing. I don't want anyone in
    this file at all. How can I get it to skip the error and just end the sub
    when this happens. Code Attached

    Application.ScreenUpdating = False
    Sheets("Daily").Select
    With ActiveSheet
    If Range("WEEK") = "WEEK 1" Then
    Sheets("Data").Select
    Application.Goto Reference:=Range("A1"), Scroll:=True
    Sheets(Array("Cover", "Weekly Gross Sheet 1", "Payroll Analysis 1")).Copy
    ActiveWorkbook.SaveAs Sheets("Cover").Range("B15").Value
    Sheets("Cover").Select
    ActiveSheet.Delete
    ActiveWindow.Close
    End If
    If Range("WEEK") = "WEEK 2" Then
    Sheets("Data").Select
    Application.Goto Reference:=Range("A1"), Scroll:=True
    Sheets(Array("Cover", "Weekly Gross Sheet 2", "Payroll Analysis 2")).Copy
    ActiveWorkbook.SaveAs ActiveSheet.Range("B15").Value
    Sheets("Cover").Select
    ActiveSheet.Delete
    ActiveWindow.Close
    End If
    End With
    Sheets("Daily").Select
    Application.Goto Reference:=Range("A1"), Scroll:=True
    Application.ScreenUpdating = True

  2. #2
    GS
    Guest

    RE: How to avoid an error dialog

    possibly:
    At the beginning of the procedure add this:

    On Error GoTo ErrorExit

    Then insert this as the lines before "End" Sub or Function:

    ErrorExit:
    Err.Clear

    -OR-
    You could use On Error Resume Next at the beginning, to suppress any error
    messages that may occur in the procedure.

    I hope this helps!
    GS

  3. #3
    justaguyfromky
    Guest

    RE: How to avoid an error dialog

    Thanks, That did the trick.

    Justa

    "GS" wrote:

    > possibly:
    > At the beginning of the procedure add this:
    >
    > On Error GoTo ErrorExit
    >
    > Then insert this as the lines before "End" Sub or Function:
    >
    > ErrorExit:
    > Err.Clear
    >
    > -OR-
    > You could use On Error Resume Next at the beginning, to suppress any error
    > messages that may occur in the procedure.
    >
    > I hope this helps!
    > GS


+ 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