cursor jumping out of current header

T

Tony Logan

I'm using a macro to append a number of files to an initial file. A problem
occurs when the first page of the initial file has content in the headers and
footers (in this case, various horizontal rules...set as page borders,
actually). When appending files, these rules appear in all subsequent files.

I tried recording a macro to solve the problem, but when I run the macro,
the cursor jumps out of the second header and moves to the first header when
the code reaches this line:
With Selection.ParagraphFormat

I've tried various things, but each time I get to the above line, the cursor
jumps to the first header. Here's the chunk of code in question:

' make sure we're in Print View
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
' unlink header on page 2 from header on page 1
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
With Selection.ParagraphFormat ' here's where the problem occurs
' delete the various page borders from the header
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
End With


Not sure if I need to rewrite the code entirely or just find a substitute
bit of code for the "With Selection.ParagraphFormat" line.
 
J

Jezebel

The trick is to write the code so you don't use the Selection object at all.
Assuming you are inserting section breaks between the inserted documents,
you can use code like

activedocument.Sections(2).Headers(wdHeaderFooterPrimary).LinkToPrevious =
false
 

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