Word automation - runtime error type mismatch

mazza

Registered User.
Local time
Today, 14:26
Joined
Feb 9, 2005
Messages
101
trying to run word automation using access 2003, but I keep getting an run time error 13, type mismatch

I have a simple test function to ensure that the coding is right but I keep getting the error on the Set WordObj = CreateObject("Word.Application") line

I have a microsoft word 11 object library reference

Function FindBMark()
Dim WordObj As Word.Application
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sql As String

' Start Microsoft Word and open the document.

Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open "c:\program files\compair service management\servicejob.dot"

' Find the bookmark and insert the text.
WordObj.ActiveDocument.Bookmarks("BKJobno").Select
WordObj.Selection.Text = ("Los Angeles")

' Close and save the document.
' WordObj.ActiveDocument.Close SaveChanges:=wdSaveChanges

' Quit Microsoft Word and release the object variable.
WordObj.Quit
Set WordObj = Nothing
End Function


any ideas whats going wrong here
 
which line is highlighted in the debug window?
 
You either need to use:
Early Binding
Dim WordObj As Word.Application
Set WordObj = New Word.Application


or
Late Binding
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")

I don't believe you can mix the two like you have.
 
I have tried both combinations

the error occors at Set wordObj = CreateObject ("Word.Application")

Am I missing a reference file although I have the word 11 library reference file ticked
 
Just a comment on the New/CreateObject - MS often recommends CreateObject when automating, also when doing early binding. Check out the explanations after the third code segment here http://support.microsoft.com/?kbid=244264

I think mayhaps the rest of the article might be interesting to the OP, too, as I'm not sure how the initial code could give RT 13, unless there's a public function with that name, ore there's something else wrong.
 
Got it working - it was this code
Late Binding
Dim WordObj As Object
Set WordObj = CreateObject("Word.Application")

Not sure what I did wrong the first time - lets call it a mistery..

Thanks for your help
 
I don't think you did anything wrong the first time, based on what you said, and the code. I think there is something wrong with the Word reference on your computer, that maybe a re-registration or something can fix.
 

Users who are viewing this thread

Back
Top Bottom