Automation Error

  • Thread starter Thread starter Joe Delphi
  • Start date Start date
J

Joe Delphi

My code looks like this:

Dim TheApp As Word.Application
Dim TheDoc As Word.Document

Set TheApp = New Word.Application

I get a runtime error on the last line that says: "Automation Error, The
specified module could not be found."

Anyone know how to fix this error?


JD
 
You probably need to set a reference to MS-Word. Open any code module, go to
Tools, then References, and scroll down until you find the Microsoft Word
Object Library. Check, the checkbox, and try your code again.
 
A missing lib reference would error out on the Dim statement, not the Set.
The OP's code works for me in O-10 (XP) and O-11 (2003). However, moving
between versions can create problems - setting a reference to Lib v.10 and
executing on a system with v.11 works - the lib reference gets updated to
v.11. But then coming back to the v.10 system, the lib reference remains v.11
and the Dim fails on "Missing Library"

For safety over multiple versions of Office, remove the reference to the
Word lib and try this (known as late binding):

Dim TheApp As Object
Dim TheDoc As Object

Set TheApp = CreateObject("Word.Application")
 
TedMi said:
For safety over multiple versions of Office, remove the reference to the
Word lib and try this (known as late binding):

Agreed.

Late binding means you can safely remove the reference and only have
an error when the app executes lines of code in question. Rather than
erroring out while starting up the app and not allowing the users in
the app at all. Or when hitting a mid, left or trim function call.

You'll want to install the reference if you are programming or
debugging and want to use the object intellisense while in the VBA
editor. Then,. once your app is running smoothly, remove the
reference and setup the late binding statements.

Sample code:
' Declare an object variable to hold the object
' reference. Dim as Object causes late binding.
Dim objWordDoc As Object
Set objWordDoc = CreateObject(" Word.Document")

For more information including additional text and some detailed links
see the "Late Binding in Microsoft Access" page at
http://www.granite.ab.ca/access/latebinding.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 
For safety over multiple versions of Office, remove the reference to the
Word lib and try this (known as late binding):

Perhaps safer. OTOH, I prefer to deal with the references problem, since my
apps are likely to have some references to deal with anyway. Early binding
allows use of Intellisense while coding. Many developers, use Early Binding
while coding, then change to Late Binding to avoid having to deal with
references. Since Early Binding also makes the code run faster, sometimes
significantly faster, and other times just slightly faster, (but always
faster) I'll just continue to use it.
 
Joe Delphi said:
My code looks like this:

Dim TheApp As Word.Application
Dim TheDoc As Word.Document

Set TheApp = New Word.Application

I get a runtime error on the last line that says: "Automation Error,
The specified module could not be found."

Anyone know how to fix this error?


JD

I don't know, cause I haven't experienced this error, but my *guess*
is that your code is valid. I would further guess that one (or more?)
of needed DLL(s) are either not where it/they should be, or are
corrupt.

A simple test - does the code work on another machine? If it does,
then I'd look at the Office installation - perhaps a Detect & Repair
or reinstallation could help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top