Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Location
    Greenville, SC
    Posts
    271

    Question Unanswered: End routine if error occurs

    I have code to save my file and make a copy of the file as a new name. All is great!
    Sometimes on error I save the file twice... or try to, and I get an error 1004.

    Is there a way for me to add in my code
    If Error 1004 then end the function?

    Below is the code I have. Where would I add the code that I need also.

    Sub Print_And_Save()
    '
    ' Print_And_Save Macro
    ' Prints Proposal, saves proposal, then saves as to Completed Proposals folder.
    '
    '
    Range("F2").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    ActiveWorkbook.Save
    Path = "C:\WINDOWS\Personal\Completed Proposals\"
    Path2 = "C:\WINDOWS\Personal\Surface Systems\"
    ActiveWorkbook.SaveAs Filename:= _
    Path & "Proposal" & _
    Str(Application.Range("N2").Value), FileFormat:=xlNormal _
    , Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False
    Range("F2").Select
    Workbooks.Open Filename:=Path2 & "Proposal for XL.xls"
    End Sub

    Thanks in advance!
    Michael
    Gotta to do some code

  2. #2
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    421
    Sub Print_And_Save()
    '
    ' Print_And_Save Macro
    ' Prints Proposal, saves proposal, then saves as to Completed Proposals folder.
    '
    '
    On error goto ErrorSaving
    Range("F2").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    ActiveWorkbook.Save
    Path = "C:\WINDOWS\Personal\Completed Proposals\"
    Path2 = "C:\WINDOWS\Personal\Surface Systems\"
    ActiveWorkbook.SaveAs Filename:= _
    Path & "Proposal" & _
    Str(Application.Range("N2").Value), FileFormat:=xlNormal _
    , Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False
    Range("F2").Select
    Workbooks.Open Filename:=Path2 & "Proposal for XL.xls"
    ErrorSaving:
    On Error goto 0
    End Sub

Posting Permissions

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