Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default 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   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid Update Links dialog in Excel 2003 Ian Chappel Links and Linking in Excel 3 June 29th 07 01:11 PM
how to avoid zero error in log log plot rgandhi1 Charts and Charting in Excel 1 February 14th 07 09:07 PM
how can i avoid an error message while printing an excel sheet solidad Excel Discussion (Misc queries) 1 August 13th 06 01:00 PM
Avoid error with simple subtraction function wjsubs[_6_] Excel Programming 1 July 9th 04 07:27 PM
How to avoid error 2015 when using ActiveCell.Offsett in own function Torben Laursen Excel Programming 2 February 18th 04 03:53 PM


All times are GMT +1. The time now is 11:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"