Adding text to the end of a Word document

B

Booch

I would like to add some text to the end of a Word document in my VC++
application, but I can't figure out how to move the cursor to the end of the
document before inserting the text. I have retrieved a Selection object for
my document and can add text to the top of the document with the TypeText()
function. What objects/functions do I need?

Thanks.

Booch
 
C

Cindy M -WordMVP-

Hi Booch,
I would like to add some text to the end of a Word document in my VC++
application, but I can't figure out how to move the cursor to the end of the
document before inserting the text. I have retrieved a Selection object for
my document and can add text to the top of the document with the TypeText()
function. What objects/functions do I need?
I encourage you to NOT use the SELECTION object unless you absolutely must.
Instead, you should be using the RANGE object. To answer your exact question
(how to enter text at the end of a document), it would go something like this,
in VB-speak:
Dim rng as Word.Range
Set rng = ActiveDocument.Content
'new line at end
rng.InsertAfter vbCR
'move the "focus" to the end
rng.Collapse Direction:=wdCollapseEnd
rng.Text = "the text at the end"
'Format this new text bold
rng.Font.Bold = 1

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
B

Booch

Thanks so much, it works great!

Booch

Cindy M -WordMVP- said:
Hi Booch,

I encourage you to NOT use the SELECTION object unless you absolutely
must.
Instead, you should be using the RANGE object. To answer your exact
question
(how to enter text at the end of a document), it would go something like
this,
in VB-speak:
Dim rng as Word.Range
Set rng = ActiveDocument.Content
'new line at end
rng.InsertAfter vbCR
'move the "focus" to the end
rng.Collapse Direction:=wdCollapseEnd
rng.Text = "the text at the end"
'Format this new text bold
rng.Font.Bold = 1

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)


This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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