Thread: edit word doc
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
LabElf LabElf is offline
external usenet poster
 
Posts: 26
Default edit word doc

You need to have the MS Word application installed to use the MS Word
functions. Assuming you're using Visual Basic 6.0, Select Project /
References ... and click the box labeled "Microsoft Word 9.0 Object Library",
and then click the "OK" button. After this, the calls to Work programming
classes should work.
--
In theory, there is no difference between theory and practice; in practice,
there is.


"Shawn G." wrote:

Dim Word As New Word.Application gives User-defined type not defined???
I am using Office 2003 if that means anything.


"Ed" wrote:

Shawn:

This code sets an object to the Word application, and then sets and object
to a single document. The object "WordDoc" is your Word document, which
can be manipulated using the Word object model. If you've set the library
reference to Word, then the Word objects, properties, and methods are
available in the VBA Editor (such as my "Dim rng As Word.Range". Also note
the ending code.

Ed

Dim Word As New Word.Application
Dim WordDoc As New Word.document
Dim rng As Word.Range

''' "doc" in the following line is a string variable
''' previously Dim'd and set to the desired
''' document's complete file path and name
Set WordDoc = Word.Documents.Open(doc)
Word.Visible = True
Set rng = WordDoc.Paragraphs.Last.Range

WordDoc.Close
Word.Quit
Set WordDoc = Nothing
Set Word = Nothing


"Shawn G." wrote in message
...
you wouldn't happen to have an explanple would you?

"Ed" wrote:

You'll have to set a library reference to the Word object library.

Then,
when you set an object to your document, you can use the Word object

model
references (line, paragraph, story, and so on) to manipulate the ranges

and
text of a Word document from within Excel VBA.
Ed

"Shawn G." wrote in message
...
I need to open a word doc and insert cell values at the end of certain
lines
from within excel. I can get the file open but how do I control where

the
text goes in the word application?

Thanks