Specifying a range within a header

D

David Cleave

Hi all

I’m using VB to produce a Word document. Is there a way to specify a Range
within a header, or can you only specify the Range that represents everything
in the header?

The VB editor will now allow me to use:

MyDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range(Start:=
something, End:= something else)

Is there another way?

Thanks again

David
 
D

Dave Lett

Hi David,

Set myRange =
MyDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range(Start:=0,
End:=0)

This represent the "start" of the Primary Header. Is there another way to
specify a range for the header, is that what you're asking? If you're trying
to set a range, then this is probably the most efficient way to do it.

HTH,
Dave
 
D

David Cleave

Hi Dave

Try that code for yourself. When I run it, I get an error which says:

Compile error: wrong number of arguments or invalid property assignment

Apparently in this context, the Range method (which we use to return a
Range) does not accept arguments.

It appears you just can't use the Start and End arguments for a Range within
a header. However, you can specify paragraphs using:

MyDocument.Sections(1).Headers(wdHeadersFootersPrimary).Range.Paragraphs(1).Range

Please tell me if there's something I'm missing.

Thanks again

David
 
D

Dave Lett

Hi David,

Sorry about the confusion.

The following snippets do the same thing:

With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
Set MyRange = ActiveDocument.Range(Start:=.Start, End:=.Start)
End With

Set MyRange =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
With MyRange
.Start = 0
.End = 0
End With

Evidently (and this is largely me just surmising from the Help file), there
is a Range method (used with Set and Start/End positions) and Range property
(can be used with Set but NOT with Start/End positions in same line). In the
first sample above, it's the Range method, in the second sample, it's the
Range property. How do I know this? Paste the code into VBA, place your
cursor in the word "Range" in each instance and then press the F1 key; the
help file raises different help topics. I have to admit that I don't get the
difference. Sorry.

HTH,
Dave
 

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