Automating Word

G

Guest

I'm trying to automate word; at first, with very simple code:

********
Sub automateWord()

Dim wordApp As Word.Application

' Create new hidden instance of Word.
Set wordApp = New Word.Application
' Show this instance of Word.
wordApp.Visible = True

With wordApp
' Code to automate Word here.
End With

wordApp.Quit
Set wordApp = Nothing
End Sub
************

I have set a reference to the Word Object Library.


When the code encounters the "Set" statement, I get the following error
message:

"Run-time error '-2147221231 (80040111)

Automation Error
ClassFactory cannot supply requested class"

If I substitute Excel for Word, everything works as expected.

What am I missing here?
 
J

John Nurick

Hi Bill,

I don't think you're missing anything. This code should work (does work
on my system). Searching groups.google.com suggests that this is an
uncommon problem caused by something having gone wrong with your Word or
Office installation. Out of curiosity I'd try
Set WordApp = CreateObject("Word.Application")
but I wouldn't expect it to work differently.

For a fix, the first thing I'd try is to re-register Word by running
winword /r

If that doesn't do the job, after that, run Office Setup and repair the
installation. After that, uninstall and re-install Office.

There's one newsgroup thread that suggests (but does not prove) a link
between this problem and Norton Antivirus 2004.
 

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

Top