Draw lines on last page

C

courtesio99

I have the following problem:

I need to run a macro to draw 2 horizontal lines on every page of a
document.(somewhere near the top left). However, the spacing between
the 2 lines should be closer to each other on the last page. The lines
are of the same spacing for the rest of the pages.

How do I do that?
 
M

Mark Tangard

There's no page object in VBA, so you'd be better off creating 2 AutoTexts, one
containing the pair of normal lines and one containing the pair of closer lines,
then placing a field in the *header* that tests for whether you're on the last
page and inserts the appropriate AutoText. For example (NOTE: UNTESTED):

First autotext (containing the normal pair of lines): "Lines1"
Second autotext (containing the closer pair of lines): "Lines2"

Field in header:

{ if { page } < { numpages } "{ autotext Lines1 }" "{ autotext Lines2 }" }

Inserting this field via code would be an exercise in masochism so I'd say make
another autotext, say, 'LineMaker' containing the entire field and insert *it*
with a macro:

Set r as Range
Set r = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
ThisDocument.AttachedTemplate.AutoTextEntries("LineMaker"). _
Insert Where:=r, RichText:=True

You'd have to experiment (probably lots) to get the two line pairs to float at
the right spot but it should work.
 

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