VBA code acting strangely

R

Rick Charnes

I have a word document with several sections, and First Page and Primary
Headers in all sections. I want set both headers of Section 2 to "Link
to Previous". This code used to work:

Selection.GoTo what:=wdGoToSection, Which:=wdGoToFirst, Count:=2
ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader
Selection.HeaderFooter.LinkToPrevious = True
ActiveWindow.ActivePane.View.SeekView = wdSeekPrimaryHeader
Selection.HeaderFooter.LinkToPrevious = True

....but for some reason all of a sudden the 'wdSeekPrimaryHeader' command
(4th line above) is now taking me to the FIRST PAGE HEADER of SECTION 3,
instead of the Primary Header of Section 2. Any idea why that might be?
Is there a better way to write this?
 
J

Jay Freedman

Hi Rick,

I never trusted that SeekView garbage anyway. Just set the links without
moving the Selection at all:

With ActiveDocument.Sections(2)
.Headers(wdHeaderFooterFirstPage).LinkToPrevious = True
.Headers(wdHeaderFooterPrimary).LinkToPrevious = True
End With
 

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