'.LinkToPrevious = True' does not work

M

Mark Goddard

Hi,

I've been experiencing some strange problems in my Word
VBA code where when setting the primary header's
LinkToPrevious property to TRUE, it remains at FALSE.

I've managed to reliably replicate something similar in a
simple document...you can create it by following the
below steps:

1) Create a blank document
2) Insert 3 next page section breaks
3) Edit the header in section 3 and turn off the "same as
previous" option.
5) In VBA, type
activedocument.Sections(3).Headers
(wdHeaderFooterPrimary).LinkToPrevious = True

After typing this command, you'll notice section 3 is
still not linked to the previous header, but section 4
has changed from being linked to not being linked.

i.e. it fails every time you try and set LinkToPrevious =
TRUE when the following section also has LinkToPrevious =
True.

The solution here is to put the cursor into section 3 and
type:
selection.Sections.First.Headers
(wdHeaderFooterPrimary).LinkToPrevious = true

This works.

Now, my problem comes when I am (inconsistently) getting
similar behaviour when setting the LinkToPrevious
property of the final section. I can't work out when
this happens or why...does anyone have any ideas?
There's nothing out there that I can find that documents
anything similar.

Cheers,

Mark
 
J

Jezebel

On first attempt I couldn't recreate your problem: I tried your steps and my
section 3 header disappeared to become 'same as' section 2, exactly as
normally expected.

Ah, but what if there is *no* section 2 header? -- then the problem is as
you describe! You can't make the header same as previous if the previous
header is empty.
 
M

Mark

Thanks, but it's my fault for not putting clear
instructions.

It happens for me, and lots of users, when the headers
are populated. It's got to be some weird Word bug but
it's proving v. hard to track down. It occurs on 97 and
2000.

I need to find out when and why a .LinkToPrevious = True
command on the final section doesn't work, when there are
headers in all sections.

Cheers,

Mark
 
M

Mark Goddard

The method I put before works on several computers here
(NT, XP, Office 97 and 2000) so I'm surprised you can't
replicate it.

Unfortunately that's the only method I've found so far.
I was hoping other people may have been in similar
situations previously but it's looking like this isn't
the case...


Thanks for your help though.

Mark
 
J

Jezebel

Just a thought: the previous header in a word document isn't necessarily
visible. For example if you add several continuous section breaks to a page,
you'll see the header for the first and the footer for the last of those
sections. The headers for the intermediate sections are not visible
anywhere, but are taken into account with the linktoprevious setting. Could
your problem be related to these non-displayed headers?


Another way to approach the issue: you can iterate through all the headers
using the StoryRange object:

Set pRange = ActiveDocument.StoryRanges(wdPrimaryHeaderStory) -- first
section header
Do until pRange is nothing
....
set pRange = pRange.next
Loop
 

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