Macro for page number

O

Outlook-tobber

If I develop a macro for pagenumbers in the heading is does not work properly.

I have to translate the handling so I hope it is understandble.
Develp Macro > insert > Pagenumber > in heading of the page > Only number 3

In the execution the macro gives an error.
Error 5941 by execution.
The asked sentence of the collection does not exists.

I get no satisfied answer of any of the dutch forums, so maybe someone in
the USA
can help me.

Thanks in advance and with regards Bernard klaver.
You are alowed to wriet me directly on; (e-mail address removed)
 
M

macropod

Hi Outlook-tobber,

Without seeing your code, it's hard to say what the problem is.

Try something based on:
Sub AddPageNumber()
With ActiveDocument
.Fields.Add Range:=.Sections(1).Headers(wdHeaderFooterPrimary).Range, _
Type:=wdFieldPage, Preserveformatting:=False
End With
End Sub

or, if you're trying to start numbering from '3' to a particular Section:
Sub AddPageNumber()
Dim oRng
With ActiveDocument
Set oRng = .Sections(1).Headers(wdHeaderFooterPrimary)
.Fields.Add Range:=oRng.Range, Type:=wdFieldPage, Preserveformatting:=False
With oRng.PageNumbers
.NumberStyle = wdPageNumberStyleArabic
.HeadingLevelForChapter = 0
.IncludeChapterNumber = False
.ChapterPageSeparator = wdSeparatorHyphen
.RestartNumberingAtSection = True
.StartingNumber = 3
End With
End With
End Sub
Simply change 'wdHeaderFooterPrimary' and the '1' in .Sections(1) to suit your requirements.
 

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