If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > End routine if error occurs

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-21-04, 16:16
surfacesys surfacesys is offline
Registered User
 
Join Date: Mar 2004
Location: Greenville, SC
Posts: 271
Question 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
Reply With Quote
  #2 (permalink)  
Old 05-24-04, 06:13
namliam namliam is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On