Paste Text (Simple Question)

J

Jake

How do I paste text (from a variable in VBA code) into a new word document? So far I have:

Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set dWord = oWord.Documents.Add

I don't know how to place the text represented by the variable strText into this document. Help?

Thanks!
Jake
 
J

Jay Freedman

Jake said:
How do I paste text (from a variable in VBA code) into a new word document? So far I have:

Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set dWord = oWord.Documents.Add

I don't know how to place the text represented by the variable strText into this document. Help?

Thanks!
Jake

Use either

dWord.Range.Text = strText

or

dWord.Range.InsertBefore strText

or (since the new document is empty, this is equivalent to)

dWord.Range.InsertAfter strText
 

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