Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove page numbers from a Word Doc 1

Status
Not open for further replies.

sheila11

Programmer
Dec 27, 2000
251
US
Hi all,

I need to remove page numbers from a Word Doc using VB/VBA. Wiil be grateful for any advice / pointers / links ... !

TIA,
Sheila
 
Hi Sheila,

Trying to Find Page Numbers is really the wrong way to go about this, and the Macro Recorder isn't going to help much in this case.

There is a Collection of Page Numbers in each Header and Footer in each Section of a Document. The easiest way to delete Page Numbers is to step through these collections ..

Code:
[blue]Sub DeletePageNumbers()

Dim objSect As Section
Dim objHF As HeaderFooter
Dim objPNum As PageNumber

For Each objSect In ActiveDocument.Sections
    
    For Each objHF In objSect.Headers
        For Each objPNum In objHF.PageNumbers
            objPNum.Delete
        Next
    Next
    
    For Each objHF In objSect.Footers
        For Each objPNum In objHF.PageNumbers
            objPNum.Delete
        Next
    Next
    
Next

End Sub[/blue]

It is also possible, though unusual, to have Page Number Fields in the main body of a document, and indeed elsewhere, but these are not part of any PageNumbers Collection and will need special treatment if you have them; please post back if that's the case.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thanks a million, Tony! That works perfectly!!

Thanks everyone.
Have a great weekend you all,
Sheila
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top