Inserting text in header when caret is in header

D

David Thielen

Hi;

How can I tell if the user has the caret in the header/footer (instead of
the document body) and how do I then both read the text at that point and
insert text at that point?
 
P

Peter Huang [MSFT]

Hi Dave,

I think you may try to take a look at the code below.
Sub Macro1()
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.TypeText Text:="AAAAAAAAAA"
Dim o As WdSeekView
o = ActiveWindow.ActivePane.View.SeekView
MsgBox o
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
o = ActiveWindow.ActivePane.View.SeekView
MsgBox o
End Sub

We can check the ActiveWindow.ActivePane.View.SeekView to know what is the
current view type.


Best regards,

Peter Huang

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.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=,
How can I tell if the user has the caret in the header/footer (instead of
the document body) and how do I then both read the text at that point and
insert text at that point?
An alternative to Peter's suggestion that returns a more general yes/no
(header/footer or not) answer is

Selection.Information(wdInHeaderFooter)

If you need to know the type, then you can use the wdHeaderFooterType
argument of the Information property (see Word's Help for more details).

As to reading the text at that point, that depends on what it is you want to
pick up? Just the user's selection? Then Selection.Text (also use this to
insert text at this point).

The entire header/footer content? Then
Dim rng as Word.Range
Set rng = Selection.Range
rng.WholeStory
MsgBox rng.Text

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

David Thielen

Hi;

One of these days I should learn VB <g>. Both explanations were clear once I
figured out the syntax.

Ok, so I have it working great for text. But I also need to be able to read
and insert fields in the header/footer (at the selection point). How can I do
that? Adding a field requires a range object.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=,
One of these days I should learn VB <g>
Ok, so I have it working great for text. But I also need to be able to read
and insert fields in the header/footer (at the selection point). How can I do
that? Adding a field requires a range object.
I think you're going to kick yourself (or thump your head on the keyboard -
whichever form of self-inflicted masochism you prefer):

Word.Range rng = WdApp.Selection.Range;

(more or less C#, off the top of my head)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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