How insert string variable into my Word document?

R

Rick Charnes

In Word 2003, I have a string of text stored in a variable. What
function do I use to insert that variable into my document? Thanks
much.
 
J

Jezebel

Get a reference to the range to which the text will be added, then use one
of the Insert methods. Eg, to add it to the end of the body --

activedocument.Content.InsertAfter MyVariable

A better method if the document location is pre-determined: insert a
DocProperty field in the document, then in your code set the property value.
 
R

Rick Charnes

I want to insert it right where the cursor is located. I don't see an
Insert.. method for this. I guess I just want to do what TypeText()
does, only with a string variable rather than raw text. Thanks for the
help.
 
J

Jezebel

You can't have looked very hard: the Selection object has the same set of
Insert methods as any other range. Or use TypeText if you wish: that takes a
string argument, which may be a literal or a variable.

Dim pText as string

pText = "This is the text to insert"
Selection.TypeText pText

or

Selection.InsertAfter pText
 

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