Creating header/footer using macros in Word 2003

S

Stéphane

Hello,

I have a macro to write but have no idea how to do it. (Starting to learn
macro in word).

The macro has to do two things.

1) Have multiple lines (variable as to the number of them) selected and
moved to the header. The lines that I have to select will have a flag to
mark the beginning and end of the wanted lines. There will also be multiple
sections in the document.

2) If a section is more than one page long, from page 1 to n-1 (n being
the total number of pages in the section) have "Continued on next page"
written in the footer of the section.

The source of the file is SAS as a RTF file that once it has gone thru the
macro, will be saved a Word 2003 DOC file.

Thanks and have a nice day.

Stephane Halle
 
D

Doug Robbins - Word MVP

For 1, is there only one instance of the flagged text in the document, or
are there separate instances for each Section of the document?

For 2, if the page numbering is set to restart at 1 for each Section, you
can use the following field construction in the footer of each Section of
the document - no macro required:

{ IF { SECTIONPAGES } > 1 { IF { PAGE } < { SECTIONPAGES } "Continued on
next page" "" } "" }

It is quite a bit more complicated if the page numbering is set to be
continuous throughout the document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP on news.microsoft.com

The following macro assumes that the flags are <Start> and <End>. You will
need to replace those with the actual flags and make appropriate adjustments
to the - 1, + 4, +& and - 5

Dim hrange As Range, htext As Range
Dim i As Long
Set hrange = ActiveDocument.Range
hrange.Start = hrange.Start + InStr(hrange, "<Start>") - 1
hrange.End = hrange.Start + InStr(hrange, "<End>") + 4
Set htext = hrange.Duplicate
htext.Start = htext.Start + 7
htext.End = htext.End - 5
With ActiveDocument
.Sections(1).Headers(wdHeaderFooterPrimary).Range.FormattedText =
htext.FormattedText
For i = 2 To .Sections.Count
.Sections(i).Headers(wdHeaderFooterPrimary).LinkToPrevious = True
Next i
End With
hrange.Delete


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

-----Original Message-----
From: Stephane [mailto:[email protected]]
Sent: Monday, February 23, 2009 7:58 AM
To:
Subject: Re: Creating header/footer using macros in Word 2003



Hello Mr. Robbins,

To answer your question, there will be separate instance for each section

the document.

Thanks for the answer for the second question.



Stephane





"Doug Robbins - Word MVP" <[email protected]> a écrit dans le message

de groupe de discussion : said:
For 1, is there only one instance of the flagged text in the document, or
are there separate instances for each Section of the document?

For 2, if the page numbering is set to restart at 1 for each Section, you
can use the following field construction in the footer of each Section of
the document - no macro required:

{ IF { SECTIONPAGES } > 1 { IF { PAGE } < { SECTIONPAGES } "Continued on
next page" "" } "" }

It is quite a bit more complicated if the page numbering is set to be
 

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