admin管理员组文章数量:1400731
I want to insert page number in the following format at the centre of my section footer. 1/10, 2/10,... 10/10
I tried the following code, this inserts 1/10 aligned at the left side of the footer.
Set rngHeader = wdDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
rngHeader.Delete
With rngHeader
'.InsertAfter Text:="Page "
'.MoveEnd wdCharacter, 0
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="NUMPAGES", PreserveFormatting:=False
.InsertAfter Text:=" / "
.Collapse wdCollapseStart
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="PAGE", PreserveFormatting:=False
End With
I am unable to control the insertion of special field. I am new to word vba.
Thanks in advance for the experts.
-- Subbu
I want to insert page number in the following format at the centre of my section footer. 1/10, 2/10,... 10/10
I tried the following code, this inserts 1/10 aligned at the left side of the footer.
Set rngHeader = wdDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
rngHeader.Delete
With rngHeader
'.InsertAfter Text:="Page "
'.MoveEnd wdCharacter, 0
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="NUMPAGES", PreserveFormatting:=False
.InsertAfter Text:=" / "
.Collapse wdCollapseStart
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="PAGE", PreserveFormatting:=False
End With
I am unable to control the insertion of special field. I am new to word vba.
Thanks in advance for the experts.
-- Subbu
Share Improve this question asked Mar 23 at 13:37 SubramanianSubramanian 1011 silver badge12 bronze badges 2- "I am unable to control the insertion of special field." is vague. Exactly what problem are you having? Using VBA to insert page numbers seems like the hard way to do this. Why not just use the program interface and add a page number? – John Korchok Commented Mar 23 at 16:30
- @JohnKorchok - I am adding NumofPages ,"/" & Page in the above code. But its appearing Page, "/" & NumofPages in the section footer. This behaviour I am unable to figure it out – Subramanian Commented Mar 23 at 17:59
1 Answer
Reset to default 1Try:
With wdDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
.Text = "//"
.Fields.Add Range:=.Characters.Last, Type:=wdFieldEmpty, Text:="NUMPAGES", PreserveFormatting:=False
.Fields.Add Range:=.Characters.First, Type:=wdFieldEmpty, Text:="PAGE", PreserveFormatting:=False
.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
本文标签: Adding page number to a section footer in custom format using vba in word documentStack Overflow
版权声明:本文标题:Adding page number to a section footer in custom format using vba in word document - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744284843a2598828.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论