For the selected section and the following one: unlink headers fromprevious section

A

andreas

Dear Experts:

Below macro unlinks the current headers from the previous section. How
has this code to be expanded if I also wanted the following section's
headers to be unlinked from the previous section?

Help is much appreciated. Thank you very much in advance. Regards,
Andreas

With Selection.Sections(1)
..Headers(wdHeaderFooterPrimary).LinkToPrevious = False
..Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
..Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
End With
 
S

Stefan Blom

You can use

With ActiveDocument.Sections(Selection.Sections(1).Index + 1)

as the first line of your code; it returns the section following the one
containing the insertion point (assuming such a section exits, which the
code doesn't test for).

An easier approach is to use a loop to access all sections:

Dim s As Section
For Each s In ActiveDocument.Sections
s.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
s.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
s.Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
Next s
 
A

andreas

You can use

With ActiveDocument.Sections(Selection.Sections(1).Index + 1)

as the first line of your code; it returns the section following the one
containing the insertion point (assuming such a section exits, which the
code doesn't test for).

An easier approach is to use a loop to access all sections:

Dim s As Section
For Each s In ActiveDocument.Sections
s.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
s.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
s.Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
Next s

--
Stefan Blom
Microsoft Word MVP









- Show quoted text -

Hi Stefan,

thank you very much for your professional help. It works as desired.
Thank you. Regards, Andreas
 
S

Stefan Blom

You are welcome.

--
Stefan Blom
Microsoft Word MVP



You can use

With ActiveDocument.Sections(Selection.Sections(1).Index + 1)

as the first line of your code; it returns the section following the one
containing the insertion point (assuming such a section exits, which the
code doesn't test for).

An easier approach is to use a loop to access all sections:

Dim s As Section
For Each s In ActiveDocument.Sections
s.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
s.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
s.Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
Next s

--
Stefan Blom
Microsoft Word MVP









- Show quoted text -

Hi Stefan,

thank you very much for your professional help. It works as desired.
Thank you. Regards, Andreas
 

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