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
 
Have you tried the Macro recorder ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Yes. Removing page number requires selecting the number on the page (Header or Footer), and the Macro records:
Selection.Delete
which is not useful at run time in VB/VBA :(

Sheila
 
This should put you into the footer:

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

Then you just need to navigate to wherever the page number would be and delete it.
 
thanx TomThumbKP! How can I select just the page number from the Footer ?

 
Well, you will essentially need to know where it is. Otherwise you will need to search for it.
 
Could you please tell me how I can search? A line of code will be of great help.
 
There are several ways. Look up InStr in the VBA help.
 
TomThumbKP,
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
gives error saying:
"Command only available in print layout view."

Sheila
 
sheila11, again play with the macro recorder while you use the menu Edit -> Search tool to find where the page number is.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Follow PHV's advice. That is how I got the command I posted above. He knows more about this than I do anyway. :)
 
Try reading this thread. It is Excel, but it should work for word as well.

thread707-816304
 
TomThumbKP, the Word and Excel PageSetup objects are VERY different.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Unfortunately Macro method isn't helping here. The Macro I get is:

Sub Macro1()
' Macro1 Macro
' Macro recorded 4/8/2004 by Sheila
'
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

ActiveWindow.ActivePane.VerticalPercentScrolled = 60

Selection.Delete Unit:=wdCharacter, Count:=1

End Sub

But the first line itself gives error when run in VB, saying "Command only available in print layout view."

 
Selection.Delete Unit:=wdCharacter, Count:=1
How have you made the selection ?
Seems you don't have used the search menu option.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Do you mean Edit-> Find tool ?
Edit -> Find doesn't find items in Header ir Footer. It's able to find it only in the body content.
 
Can you please post an example of text you want to modify, expected result and where it is located in the document.
 
I need to remove page numbers from a Word Doc using VB/VBA.

I guess when you insert page numbers, they get inserted into the Header or the Footer as per your choice. I need to delete the page numbers inserted by previous user of the document.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top