Home |
Search |
Today's Posts |
|
#1
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how do i count how many people are working between two times in e | Excel Worksheet Functions | |||
Working time and days | Excel Worksheet Functions | |||
Working time and days | Excel Discussion (Misc queries) | |||
Trace Dependents and Precedents not working | Excel Worksheet Functions | |||
Drop-down boxes stopped working | Excel Discussion (Misc queries) |