Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-05-2015, 06:44 AM
rich_cirillo rich_cirillo is offline Enter page numbers Windows 7 64bit Enter page numbers Office 2010 64bit
Novice
Enter page numbers
 
Join Date: Sep 2012
Posts: 27
rich_cirillo is on a distinguished road
Default Enter page numbers

Hi



Would there be a VBA Code for inserting page numbers to word document. The VBA code would insert a page number from a selected starting page. The text would be Page 1 and then number every page after the selected starting page. This would be inserted at the bottom , left hand side of each page

Thanks you

Rich
Reply With Quote
  #2  
Old 05-05-2015, 07:11 AM
gmayor's Avatar
gmayor gmayor is offline Enter page numbers Windows 7 64bit Enter page numbers Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You don't really need a macro to do this, but the following will do it. There are however provisos and the main one revolves around how the footers are configured. There are potentially lots of footer ranges in a document - three to each section. This macro addresses only the primary footer.

Code:
Option Explicit

Sub AddPageNumbers()
Dim oRng As Range
Dim oFooter As HeaderFooter
    Set oRng = ActiveDocument.Bookmarks("\page").Range
    oRng.Collapse 1
    oRng.InsertBreak wdSectionBreakContinuous
    Set oFooter = oRng.Sections(1).Footers(wdHeaderFooterPrimary)
    oFooter.LinkToPrevious = False
    If Len(oFooter.Range.Text) > 1 Then
        oFooter.Range.InsertParagraphAfter
    End If
    With oFooter.PageNumbers
        .NumberStyle = wdPageNumberStyleArabic
        .HeadingLevelForChapter = 0
        .IncludeChapterNumber = False
        .ChapterPageSeparator = wdSeparatorHyphen
        .RestartNumberingAtSection = True
        .StartingNumber = 1
    End With
    Set oRng = oFooter.Range
    With oRng
        .Collapse 0
        .Text = "Page "
        .Collapse 0
        .Fields.Add oRng, wdFieldPage, , False
        .ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With
lbl_Exit:
    Set oFooter = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I edit my TOC to reference the section numbers instead of the page numbers??? mikey386 Word 0 12-17-2014 02:34 PM
Enter page numbers How to enter different texts on the bottom of the page? Pws Word 5 02-24-2014 11:54 PM
Enter page numbers Page breaks....Ctrl-Enter..help is appreciated typing33 Word 2 02-10-2013 02:19 PM
How do I refer to page numbers, when the numbers change as I prepare the document? StevenD Word 5 11-29-2012 12:52 AM
Enter page numbers Page Numbers Not Matching Chapter Numbers gracie5290 Word 1 02-02-2012 11:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft