inserting template at the start of doc

Z

Zippy

I am working with Word automation via Access 97.

I have two Word templates. I open Template1 and then insert Template2
at the end using:

ObjWord.ActiveDocument.Characters.Last.Select
ObjWord.Selection.InsertBreak (Word.WdBreakType.wdPageBreak)
ObjWord.Selection.InsertFile (Template2)

I then decided (due to technical reasons) to first open Template2 and
then add Template1 to the start. I thought I would do it by just
adjusting the code slightly:

ObjWord.ActiveDocument.Characters.First.Select

and then inserting the file. The problem with this is that the first
letter on the page gets selected (well, I did specify 'Select', so what
did I expect) and then over-written when the page is added.

How do I move to the beginning of the page without any text being
selected?

Thanks.
 
G

Graham Mayor

From Word it would be

Dim orng As Range
Set orng = ActiveDocument.Range
With orng
.Collapse wdCollapseStart
.InsertFile Template2
End With

so I guess

With objWord
Set orng = .ActiveDocument.Range
With orng
.Collapse wdCollapseStart
.InsertFile Template2
End With
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Z

Zippy

Great! Thanks.

Another question:

I want a page break between Template1 (newly added at start of doc) and
Template2 (existing doc) so that Template2 is pushed on to a new page.

I tried putting an

.InsertBreak (Word.WdBreakType.wdPageBreak)

both before and after these two lines of code

.Collapse wdCollapseStart
.InsertFile Template1

but it puts the break at the start of the doc rather than between the
two docs. What should I be doing?

Thanks once again.
 
J

Jean-Guy Marcil

Zippy was telling us:
Zippy nous racontait que :
Great! Thanks.

Another question:

I want a page break between Template1 (newly added at start of doc)
and Template2 (existing doc) so that Template2 is pushed on to a new
page.

I tried putting an

.InsertBreak (Word.WdBreakType.wdPageBreak)

both before and after these two lines of code

.Collapse wdCollapseStart
.InsertFile Template1

but it puts the break at the start of the doc rather than between the
two docs. What should I be doing?

Insert the break BEFORE the file... Try something like this:

With orng
.Collapse wdCollapseStart
.InsertBreak (Word.WdBreakType.wdPageBreak)
.MoveStart wdCharacter, -1
.Collapse wdCollapseStart
.InsertFile Template2
End With
 
Z

Zippy

Thank you. That did it.

Jean-Guy Marcil said:
Zippy was telling us:
Zippy nous racontait que :

Insert the break BEFORE the file... Try something like this:

With orng
.Collapse wdCollapseStart
.InsertBreak (Word.WdBreakType.wdPageBreak)
.MoveStart wdCharacter, -1
.Collapse wdCollapseStart
.InsertFile Template2
End With
 

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