Inserting at end of document

O

O.B.1

Hi all,

i'm building a document generator using VB6, however
I'm not quite used to the word object model. I was
wondering if anyone can tell me how to insert a page
break at the end of the document (there are several
annexes to be added at the end, each one starting on a
new page).

This is a part of what I've got coded so far:
------------------
Set objWordApp = New Word.Application
objWordApp.Visible = True
Set objWordDoc = objWordApp.Documents.Add
("templatepath", , , True)

For intCount = 0 to objColAnnex.Count - 1
'in a loop, I would add each text from a annex classobject
'followed by a pagebreak, or first a pagebreak and then
followed by the text, whichever is the easiest.
Next intCount
---------------------

Is there anyone who could complete the code above, within
the for-next loop? I've tried to work with the
selectionobject like this:
Set sel = objWordApp.Selection
sel.MoveRight unit:=wdStory, Count:=1
sel.InsertBreak Type:=wdPageBreak
but I keep getting errormessages (bad parameter)

Thanks for your help!
Regards,
O.B.1
 
H

Helmut Weber

Hi,
I would suggest creating a new object (R)
and let it be "objWordDoc.range".
set R = objWordDoc.range
Then you modify your loop:
r.insertafter Chr$(12)
r.insertafter "Text1"
For intCount = 0 to objColAnnex.Count - 1
R.insertafter Chr$(12)
R.insertafter aString$(intcount) ' or whatever
Next intCount
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
V

VBA Coder

To insert a Page Break is as simple as:

ActiveDocument.Select
With Selection
' Move to the End of the Document
.EndKey Unit:=wdStory
' Insert a Page Break
.InsertBreak Type:=wdPageBreak
End With


This of course was done within Word 2000 using VBA.
 
H

Helmut Weber

Hi,
try exploring the Range-Object.
It's much faster and sometimes more versatile
than "selection", as I was told half a year ago,
and it was a good advice.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
 
V

VBA Coder

Yes, the range object is very powerful and should be used as I am starting
to learn.

Helmut, please check out my post on Dec-3-2003, to this newsgroup entitled
"Word 2000: Formatting words within a Bookmark", where I am trying to
manipulate a range and see if you can give me any advice.
 

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