Discussion:
How insert string variable into my Word document?
(too old to reply)
Rick Charnes
2007-02-22 22:29:36 UTC
Permalink
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.
Jezebel
2007-02-22 22:35:33 UTC
Permalink
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.
Post by 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.
Rick Charnes
2007-02-22 23:14:57 UTC
Permalink
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.
Post by 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.
Post by 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.
Jezebel
2007-02-23 01:31:21 UTC
Permalink
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
Post by 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.
Post by 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.
Post by 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.
Loading...