My bad about the over posting. Wont happen again. I have one more
question. this code works like a charm but when i then go in to create a
macro to place page numbers at the bottom of the active document...nothing
shows up. Does this code kill any footers/headers for good? My thinking
was to delete any extra crap that i didnt need and then add page numbers.
Help
Sub KillHeaders()
Dim oSection As Section
Dim oHeadFoot As HeaderFooter
For Each oSection In ActiveDocument.Sections
For Each oHeadFoot In oSection.Headers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Delete
Next
Next
End Sub
Hi,
The code I posted on works on the headers - anything in the footers is left
alone.
Presumably, you'd be adding the page numbers to the target document, not the
source documents. In that case, simply inserting a page number field in the
footer of the target document should suffice.
Cheers
> My bad about the over posting. Wont happen again. I have one more
> question. this code works like a charm but when i then go in to create a
[quoted text clipped - 13 lines]
> Next
> End Sub
Casey Mac - 28 Oct 2005 16:00 GMT
The code you gave worked slick! But i had to alter it later to also do and
footer information. See below. I am trying to get the page number inserted
automatically and even when i do it manually it doesnt work. Please see
below.
Sub KillHeadersFooters()
Dim oSection As Section
Dim oHeadFoot As HeaderFooter
For Each oSection In ActiveDocument.Sections
For Each oHeadFoot In oSection.Footers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Delete
Next
Next
For Each oSection In ActiveDocument.Sections
For Each oHeadFoot In oSection.Headers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Delete
Next
Next
End Sub
Then I try and have the user run this code to reinsert page numbers into
that active document
Sub InsertPageNum()
Selection.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberCenter, FirstPage:=False
End Sub
Greg - 28 Oct 2005 16:42 GMT
Thanks for your promise not to cross posts in the future ;-)
Try this (Note there will be no page number on the first page):
Sub KillHeadersFooters()
Dim oSection As Section
Dim oHeadFoot As HeaderFooter
For Each oSection In ActiveDocument.Sections
For Each oHeadFoot In oSection.Footers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Delete
On Error Resume Next
oHeadFoot.LinkToPrevious = True
On Error GoTo 0
Next
For Each oHeadFoot In oSection.Headers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Delete
On Error Resume Next
oHeadFoot.LinkToPrevious = True
On Error GoTo 0
Next
Next
ActiveDocument.Sections(1).Footers(1).PageNumbers.Add
PageNumberAlignment:= _
wdAlignPageNumberCenter, FirstPage:=False
End Sub
Casey Mac - 31 Oct 2005 04:24 GMT
Greg your code works perfectly but i have one question. I tried altering it
so that the page would a page AutoTextEntries("Page X of Y") but i cant get
it to work. can you help...Please :>
ActiveDocument.Sections(1).Footers(1).PageNumbers.Add
PageNumberAlignment:= _
wdAlignPageNumberCenter, FirstPage:=False
Greg - 31 Oct 2005 05:03 GMT
Remeber, you promised no more cross posting.
Try:
Sub KillHeadersFooters()
Dim oSection As Section
Dim oHeadFoot As HeaderFooter
Dim oRng As Range
For Each oSection In ActiveDocument.Sections
For Each oHeadFoot In oSection.Footers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Delete
On Error Resume Next
oHeadFoot.LinkToPrevious = True
On Error GoTo 0
Next
For Each oHeadFoot In oSection.Headers
If Not oHeadFoot.LinkToPrevious Then oHeadFoot.Range.Delete
On Error Resume Next
oHeadFoot.LinkToPrevious = True
On Error GoTo 0
Next
Next
Set oRng =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=oRng,
RichText:=True
End Sub