Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Handling Errors When Opening Word Docs From Excel VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chrisso - 24 Jan 2008 10:24 GMT
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
ilia - 24 Jan 2008 17:55 GMT
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.

> Hi All
>
[quoted text clipped - 24 lines]
>
> Chrisso
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.