Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All
I have written some logic in Excel VBA which opens Word files and then does some processing. I am having trouble catching all the errors from opening the Word files - my code is: On Error GoTo OpenError Word.Application.DisplayAlerts = False Word.Application.Documents.Open sFullPathAndName, ReadOnly:=True bOpenedOK = True Examine_ActiveDocument Word.Application.Documents(fTarget.Name).Close False OpenError: If Not bOpenedOK Then Record_Error When my code tries to open a corrupted Word file (which it cannot open) the error handling above does not catch it and the error fails my search. I, of course, want it to keep running until it has examined all the Word files. When you manually try to open these files Word says "Word experienced an error trying to open the file." Why does my error handling not catch this case? Thanks in advance for any ideas or suggestions, Chrisso |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Add this line to your declaration section:
Dim myDoc as Word.Document Change your Open line to: Set myDoc = Word.Application.Documents.Open sFullPathAndName, ReadOnly:=True Add this code: If myDoc Is Nothing Then Record_Error On Error GoTo 0 Hope that helps. On Jan 24, 5:24 am, Chrisso wrote: Hi All I have written some logic in Excel VBA which opens Word files and then does some processing. I am having trouble catching all the errors from opening the Word files - my code is: On Error GoTo OpenError Word.Application.DisplayAlerts = False Word.Application.Documents.Open sFullPathAndName, ReadOnly:=True bOpenedOK = True Examine_ActiveDocument Word.Application.Documents(fTarget.Name).Close False OpenError: If Not bOpenedOK Then Record_Error When my code tries to open a corrupted Word file (which it cannot open) the error handling above does not catch it and the error fails my search. I, of course, want it to keep running until it has examined all the Word files. When you manually try to open these files Word says "Word experienced an error trying to open the file." Why does my error handling not catch this case? Thanks in advance for any ideas or suggestions, Chrisso |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Opening word docs in excel | Excel Discussion (Misc queries) | |||
Microsoft Visual Basic errors displaid when opening Microsoft Word 97 & Excel (7 | Setting up and Configuration of Excel | |||
Import cells from excel into word and create multiple word docs | Excel Programming | |||
Embedding Word Docs into Excel Worksheets and Then Printing The Word Docs | Excel Worksheet Functions | |||
converting excel docs to word docs | New Users to Excel |