Automation between Excel and Word

J

James Wagman

I need to invoke an existing Word document from within Excel VBA. I
know Excel but not Word VBA. How can I invoke the Word object, then
copy all of the file's contents and dump it into Excel? Thanks.
 
J

Jezebel

Copy the file's contents is easy, but the 'dump it into Excel' is less than
obvious.

Dim pWordApp as object
Dim pWordDoc as object

Set pWordApp = CreateObject("Word.Application")
Set pWordDoc = pWordApp.Documents.Open(FileName:="MyFile.doc")

What you do after that depends on your spreadsheet. You can refer to the
content as a whole using pWordDoc.Content (which you could copy, or insert
directly into your spreadsheet). You can iterate the content of the document
by word, paragraph, etc and deal with the bits one at a time.

BTW, Excel can open a Word document by itself, if you have the converter
installed.
 

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