Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Bill
 
Posts: n/a
Default Error Handler Not Working

Hello,

I have a macro that first tries to open a Word document with a particular
file name that is built from various pieces of data being processed by the
macro. Before attempting this, I have set the error handler:

For x = 1 to 5
On Error GoTo myOpenNewDoc
Set myDoc = myDocApp.Documents.Open(myDirectory & myFileName & x &
".doc")
GoTo Procede

myOpenNewDoc:

Set myDoc = myDocApp.Documents.Add
myDoc.SaveAs (myDirectory & myFileName & x & ".doc"

Procede:
<...
Next x

The idea is to open the document if it already exists, or to create it if it
does not. This seems to work when x = 1, but for each subsequent pass I get
the following error:

Run-Time Error '5174':
This file could not be found.
Try one or more of the following:
* Check the spelling of the name of the document.
* Try a different name
(C:\WorkingDirectory\ProjectA\...\ProjectA_Locatio n2.doc)

When I click "Debug" it highlights the first "Set" command above. This is
exactly the error I am trying to handle by jumping to myOpenNewDoc:. It
seems to be ignoring the "On Error" statement.

I think there is an easier way to do this, but regardless I want to know why
my error handler is being ignored. Does anyone have any advice?

Thanks,

Bill


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
how do i count how many people are working between two times in e APYDS Excel Worksheet Functions 4 August 16th 05 08:11 PM
Working time and days Nortos Excel Worksheet Functions 5 May 6th 05 04:17 PM
Working time and days Nortos Excel Discussion (Misc queries) 1 May 6th 05 03:47 PM
Trace Dependents and Precedents not working Manish Excel Worksheet Functions 0 April 11th 05 09:39 PM
Drop-down boxes stopped working Dave Excel Discussion (Misc queries) 1 April 4th 05 06:13 PM


All times are GMT +1. The time now is 06:45 PM.

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

About Us

"It's about Microsoft Excel"