How do I hit the header/footer in Word?

D

David Thielen

Hi;

When editing text in a Word document I use Application.Selection.Range -
getting it for the present caret position, setting it and changing the text
of it to edit/delete text.

But how do I do this for text in the header or footer? They are not the
Document so I can't use Application.ThisDocument.Range to select part of it.

How do I do this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
W

Wei Lu [MSFT]

Hello Dave,

I record a macro in word.

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="Hello!"
Selection.TypeParagraph
Selection.TypeBackspace
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

You may try this code to modify the header and footer.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

It looks like the Selection object has a HeaderFooter property and that is
null if in the main doc and is non-null (and has some useful info) if you are
in the header/footer.

So it appears the solution is to work with the Selection object as it is set
for the main doc, header, etc - wherever the selection is.

Follow-on qiestion, how can I walk all of the header/footer sets of text?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
D

David Thielen

Hi;

More questions on Selection and Range objects and the main
document/header/footers:

1) Is a Range object tied to the main document or header? Or is it just a
length that can be used with anything?

2) If it is attached, how can I create a Range object tied to a header?

3) If I do rangeX = rangeY - that is just copying a pointer and any changes
to one will be to the other too - correct?

4) How can I get fields in the header/footer that the caret is in (if the
caret is in a header or footer)?

5) How can I walk through all headers & footers, both their text and their
headers/footers?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
W

Wei Lu [MSFT]

Hello Dave,

I would like to suggest you check this KB article to find whether it is
helpful.

How to automate Word to set and retrieve section header and footer
information
http://support.microsoft.com/kb/269565/

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Hi;

That article shows how to create a section and header but I couldn't find
anything on how I should:

1) Determine from the Selection object what the selection is in - main
document or which header/footer, or ???

2) How can I walk all of the headers & footers in the document?

3) In a given header/footer, how can I get the range of the entire object
and all fields in that object?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
W

Wei Lu [MSFT]

Hello Dave,

To retreive all the headers and footers, you may use the following:

With ActiveDocument
.PageSetup.DifferentFirstPageHeaderFooter = True
.Sections(1).Footers(wdHeaderFooterFirstPage) _
.Range....

End With


Hope this helps.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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