Selecting All Text in Header

  • Thread starter Doug Robbins - Word MVP
  • Start date
D

Doug Robbins - Word MVP

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Select

should do it as using

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Delete

deletes everything, including a text box in the header.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
L

LA Lawyer

I want to select everything (text and possibly even a text box) in a header.
How do I do that?
 
G

Graham Mayor

There are three headers (and three footers) associated with each section in
the document. Which header do you have in mind and what do you want to do
with the header having selected it?

The following will address all the headers in the document and assign them
in turn to the range named oRng. If you want to be more selected you can add
extra code to do that.

Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oRng As Range
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
Set oRng = oHeader.Range
'do what you want with oRng (the header) here e.g.
oRng.Delete
Next oHeader
Next oSection


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
I

iris b

Hi Graham,

I have a problem that is similar to the above one... with a couple of changes:

I vave several sections in a document.

I want to delete all the footers from section 2 to the last section of the document....

I have tried and tried... with no luck... it doesn't work...

I will be very grateful if you can help me with this problem...
this is the code I have:

Sub try()
Dim sec As Section
Dim cnt As Integer
cnt = ActiveDocument.sections.Count

For Each sec In ActiveDocument.sections
WordBasic.ViewFooterOnly
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Next

End Sub

this code only erases the footer of the first section and not the rest of them... this is exactly the oposit of what I need...
I need it to erase all the footers of sections 2 to the last section.

thank you

Iris
 
S

Stefan Blom

Unlink the sections and then delete the footers that you want to get rid of:

Sub UnlinkAndDelFooters()
Dim s As Section
Dim i As Long

If ActiveDocument.Sections.Count < 2 Then
Exit Sub 'do not run if only 1 section in doc
End If

For Each s In ActiveDocument.Sections
s.Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
s.Footers(wdHeaderFooterFirstPage).LinkToPrevious = False
s.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
Next s

For i = 2 To ActiveDocument.Sections.Count
ActiveDocument.Sections(i).Footers(wdHeaderFooterEvenPages).Range.Text = ""
ActiveDocument.Sections(i).Footers(wdHeaderFooterFirstPage).Range.Text = ""
ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).Range.Text = ""
Next i
End Sub

-- 
Stefan Blom
Microsoft Word MVP




---------------------------------------------
"iris b" wrote in message
Hi Graham,

I have a problem that is similar to the above one... with a couple of changes:

I vave several sections in a document.

I want to delete all the footers from section 2 to the last section of the document....

I have tried and tried... with no luck... it doesn't work...

I will be very grateful if you can help me with this problem...
this is the code I have:

Sub try()
Dim sec As Section
Dim cnt As Integer
cnt = ActiveDocument.sections.Count

For Each sec In ActiveDocument.sections
WordBasic.ViewFooterOnly
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Next

End Sub

this code only erases the footer of the first section and not the rest of them... this is exactly the oposit of what I need...
I need it to erase all the footers of sections 2 to the last section.

thank you

Iris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top