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

Re: Specifying a range within a header by Dave

Dave
Wed Jun 22 09:03:18 CDT 2005

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
"David Cleave" <DavidCleave@discussions.microsoft.com> wrote in message
news:C339BABD-0E59-4937-AB78-7060759E3E13@microsoft.com...
> 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



Re: Specifying a range within a header by DavidCleave

DavidCleave
Thu Jun 23 03:13:06 CDT 2005

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

"Dave Lett" wrote:

> 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
> "David Cleave" <DavidCleave@discussions.microsoft.com> wrote in message
> news:C339BABD-0E59-4937-AB78-7060759E3E13@microsoft.com...
> > 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
>
>
>

Re: Specifying a range within a header by Dave

Dave
Thu Jun 23 08:19:07 CDT 2005

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

"David Cleave" <DavidCleave@discussions.microsoft.com> wrote in message
news:1BF79382-A619-4C3A-B4E9-C01CDF319D35@microsoft.com...
> 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
>
> "Dave Lett" wrote:
>
>> 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
>> "David Cleave" <DavidCleave@discussions.microsoft.com> wrote in message
>> news:C339BABD-0E59-4937-AB78-7060759E3E13@microsoft.com...
>> > 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
>>
>>
>>