Opening Word document using VBA from Excel module

G

Gesualdo

I want users of my Excel system to be able to open a Word user manual by
clicking a button, but I'm having trouble working out the VBA code to do
this. I can activate Word, but I can't then open a document in it.

Help would be much aprreciated!
 
J

Jonathan West

Gesualdo said:
I want users of my Excel system to be able to open a Word user manual by
clicking a button, but I'm having trouble working out the VBA code to do
this. I can activate Word, but I can't then open a document in it.

Help would be much aprreciated!

Take a look here

Control Word from Excel
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
G

Gesualdo

That's great but at

Set oWord = New Word.Application

I get the error message "ClassFactory cannot supply requested class."

I've got round this by using ActivateMicrosoftApp but it would be good to
know why this isn't working.

Thanks for the help.
 
J

Jonathan West

Gesualdo said:
That's great but at

Set oWord = New Word.Application

I get the error message "ClassFactory cannot supply requested class."

I've got round this by using ActivateMicrosoftApp but it would be good to
know why this isn't working.

Thanks for the help.

Hmm. Try late binding instead. if you want to attach to an existing instance
of Word, use this

set oWord = GetObject(, "Word.Application")

If you want to start a new instance of Word, try this

set oWord = CreateObject("Word.Application")


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
L

Lynda

I have tried the late binding, but still receive the error message
"-2147221231 Automation error ClassFactory cannot supply requested class".

The VBA code is in MS Access. I have the following:
Dim appWord as New Word.Application
Dim appExcel as New Excel.Application

The following line of code works
strCaption = appExcel.Caption

The following line of code causes the Automation Error
appWord.Visible = True

I am running Windows XP SP1 on a device that has both Office XP Pro and
Office 2003 Pro installed. I have tried the above code with references to
WORD 10 and to WORD 11, getting the same error message. Interesting in that
Microsoft WORD is not listed in my reference drop down. I had to browse to
find the file. (The first time I included the reference, but before I ran
the code, the WORD 11 reference was listed.)

I have run "repair" on Office 2003 and that did not change the results.

I have another device, Windows XP Pro SP2 with only Office 2003 Pro and this
code works just fine.

I am very reluctnat to apply XP SP2 to this device as I am running Studio
2003 and many peers have had problems with Studio 2003 after installing SP2.

I would appreciate any assistance with getting past this error. My thanks
in advance.
 
J

Jay Freedman

I'm very surprised that you haven't run into other problems on this
system while simply trying to use one copy of Office or the other.
Multiple versions of Word on the same partition (and similarly for the
other Office apps) use the same sets of registry entries in many
cases. Each time you start one version after having used the other
version, you typically get a prompt to rerun the installer because the
registry appears to be corrupted.

I suspect that the section of the registry dealing with COM
configuration of the Office apps has reached a state where some
entries point to Word 2002 and other entries point to Word 2003,
leaving the whole thing inoperable.

The proper solution is to remove both versions completely, and then
reinstall just one version. If you need access to both versions at
different times, you can set up two independent Windows partitions
with dual boot, or you can use something like Virtual PC or VMWare to
set up a virtual machine for the second Office version.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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