PDA

View Full Version : Word advice on "insert"



jwise
04-16-2015, 07:54 AM
I'm trying to build a series of one page documents. In the past, each page was a template and I had bookmarks in this template which I filled in with values and progressed to the next page. Now the requirements are different. The template is now about half the page, then a variable length center section, and finally a small template at the bottom of the page. I previously used "Range" to maneuver in this document.

I have no problem with the first template and correctly fill in the values. I fill in the lines in the second section. When I "insert" the third piece (another template), it goes before the second section instead of after.

What I'd really like to do is treat each "page" as if it were a single document. Here's the relevant code:

rngDoc.Collapse wdCollapseEnd

rngDoc.InsertFile fileName:="D:\Recap\Recap_Form_Pat1.dot"

rngDoc.SetRange Start:=rngDoc.End, _
End:=wrdApp.ActiveDocument.Range.End

The above code correctly inserts the first template. The following code adds the variable data after the template. The section is dummy code which creates a series of lines like "This is line 01" etc for the maximum size.

rngdoc.SetRange Start:=wrdApp.ActiveDocument.Range.Start, _
End:=wrdApp.ActiveDocument.Range.End

For i = 1 To ctLoop Step 1
txt2 = txt1
ptrn2 = Format(i, ptrn1)
txt2 = txt2 & ptrn2 & vbCr
rng1.Collapse Direction:=wdCollapseEnd
rng1.InsertAfter (txt2)
Next i

The following code attempts to insert the last template, but it goes before the second section instead of after.

wrdApp.ActiveDocument.Range.Collapse Direction:=wdCollapseEnd

wrdApp.ActiveDocument.Range.InsertFile _
fileName:="D:\Recap\Recap_Form_Pat2.dot"

My research says I can do this with "Range" or "selection", and I really don't know the right way.

If the code looks a little strange, it's because it's actually in an Excel macro which is using Word to construct the one page summary report. Although I have written several Excel macros, this is my first attempt at anything like this via Word.

It is Office 2010.


Thanks for any advice.