View Full Version : Word automation late binding - trapping errors?
Movian
02-03-2015, 06:23 AM
Hey so I have been having problems tracking down some minor issues recently...
it seems that when I use latebinding to utelize word automation (we need to as our clients use a number of different versions of office 2007-2012) if there is a problem in the system the error does not get trapped. Instead of providing an end/ Debug dialogue box outlining the problem, code execution simple stops at that point and the system continues.
forcing an error to show does not work (on error goto err).
Any suggestions for how to trap errors in these sections ?
Tommy
02-03-2015, 02:35 PM
If you are running code inside of word, from an outside program do not read any further, I will just waste your time.
When I was coding for Word automation for machines that were running at 350 MHz, I had to place doevents in to give word time to open the file, update a formfield or what ever. I was able to trap the errors, but they didn't show up until afterward. My program had already crashed. I would post code that will allow you to get around all of my issues, but I would not recommend using it. :) Pretty bad I might say.
The below code is not recommended at all! I am posting just to show what I had to go through to get it to work. I have not run this program since they came out with machines that are 1 GHz much lees the quad cores and all. One thing I did do that helped a lot was to make word visible and see what it was doing. I did get error numbers and had to do a lot of google searches to find what was going on, I was still learning then, now also. :)
Public Sub ActivateWrdDoc(Optional SeamDoc As String)'Dim aasd As Range
On Error Resume Next
Set wrd = Nothing
Set WordDoc = Nothing
Set WrdDFF = Nothing
'Set wrd = GetObject(, "Word.Application")
Set wrd = New Word.Application
If Err.Number <> 429 And Err.Number <> 0 Then
'MsgBox Err.Number
Set WordDoc = wrd.ActiveDocument
Call KillWrd
If Err.Number = 91 Then
wrd.Quit
Set wrd = Nothing
Set WordDoc = Nothing
Set WrdDFF = Nothing
Err.Clear
End If
Err.Clear
On Error GoTo 0
'Set wrd = CreateObject("Word.Application")
Set wrd = New Word.Application
End If
If Err.Number = 429 Or Err.Number = 462 Then
Err.Clear
On Error GoTo AGAIN
'Set wrd = CreateObject("Word.Application")
Set wrd = New Word.Application
End If
wrd.Visible = False
'wrd.Visible = True
On Error GoTo AGAIN
Let me know if this helped or this shows you a direction. I might be able to help some more.
What errors are you getting?
What makes you think late binding is the issue?
Do your users have full versons of Access or runtime?
What does 'the code stops and the system continues' mean?
Is word visible? Do you turn off pop up messages in your code?
On error goto is the most basic form of error handling.
When working with files or or external objects I would use on error resume next and check the error object at each important step that is likely to produce an error.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.