page number in the Footer

A

Associates

Hi,

I need help with accessing to the Footer in the word. I have a template that
allows users to create a report for them. The report is made up of sections
such as Preface, Executive Summary, Sections, and so on in that order. The
way it inserts the sections in the report is by using autotexts. So i have
autotexts for Preface, autotexts for Executive Summary, and so on.

My problem is with the page number in the footer for these sections in the
report. When the user select Preface, the page number of the Preface should
start with number 1. The rest of the sections will have their page number set
to continue. If the user starts the report by selecting Executive Summary,
then the page number will start with number 1 in the Executive Summary's
footer. The rest of the sections after Executive Summary section will
continue from there.

Here is my code to insert 'preface'
ActiveDocument.AttachedTemplate.AutoTextEntries("preface").Insert _
Where:=Selection.Range, RichText:=True

'ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

'With Selection.HeaderFooter.PageNumbers
' .NumberStyle = wdPageNumberStyleArabic
' .HeadingLevelForChapter = 0
' .IncludeChapterNumber = False
' .ChapterPageSeparator = wdSeparatorHyphen
' .RestartNumberingAtSection = True
' .StartingNumber = 1
'End With

I tried with the code that are commented but did not get it to work.

Thank you in advance
 
G

Graham Mayor

If you start with the basic document, and set the numbering in that document
to start from 1 (as opposed to continue from previous section) then include
a section break at the end of the stored preface autotext, when you add the
preface and its section break to the start of the document, the numbering
will restart at 1 after the preface and your macro can simply be

Selection.HomeKey Unit:=wdStory
ActiveDocument.AttachedTemplate.AutoTextEntries("Preface").Insert _
Where:=Selection.Range, _
RichText:=True

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Associates

Thank you Graham for your reply.

I apologise for forgetting to mention that there is the coverpage autotext
that should always go first in the document, then followed by preface or
executive summary or sections or other sections in the report depending on
the user selection on the userform.

If i put the following code, this will bring that section to the first page.
However, i want the coverpage autotext to be inserted first in the document
before any other user-selected sections.

It will work if i set the numbering in that document (for preface autotext)
to start from 1 then include a section break at the end. It will start from 1
when added into the document. But my question is if i do the same for all the
other autotexts (executive summary, sections, and others) that is to start
from number 1 (the reason is simply because we just don't know what sections
user want to insert first after the coverpage autotext), then these autotexts
will start from 1 if they all get selected by user. This will not work for me.

Thank you in advance
 
G

Graham Mayor

OK, in that case I think I would be inclined not to worry about the page
numbering until the document is assembled, then address each section and
apply the appropriate numbering then.

Start with (say) the following in the footer of the document you start from.

{ IF { Page } = 0 "Page { Page }" ""}

If you number the cover page as 0 you won't display a number in the footer
of the cover. The rest of the sections, however many, can be addressed
according to the final order they appear in the document - something along
the lines of

Dim i As Variant
With ActiveDocument
'Cover
With .Sections(1).Footers(wdHeaderFooterPrimary)
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = 0
End With
'Preface'
With .Sections(2).Footers(wdHeaderFooterPrimary)
.LinkToPrevious = True
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = 1
End With
'First page of document
With .Sections(3).Footers(wdHeaderFooterPrimary)
.LinkToPrevious = True
.PageNumbers.RestartNumberingAtSection = True
.PageNumbers.StartingNumber = 1
End With
'Rest of document
For i = 4 To .Sections.Count
With .Sections(i).Footers(wdHeaderFooterPrimary)
.LinkToPrevious = True
.PageNumbers.RestartNumberingAtSection = False
End With
Next i
End With

Presumably you can evaluate which section refers to which inserted text
(based upon the procedures used to insert them) so you can modify the basic
concept to suit your requirements. There may be another way to do it, but I
can't think of it.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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