PDA

View Full Version : LinkToPrevious Property



ronstarr
12-06-2007, 02:21 PM
There are many posts on how to go through each section of your document and set the HeaderFooter LinkToPrevious property, however how do you check to see what it is set to in a given section? I want to paste something into each section's header, but not if the LinkToPrevious property is True (because it will be pasted in essence twice).

TonyJollans
12-06-2007, 03:10 PM
For Each S In ActiveDocument.Sections
If S.Index > 1 Then
For Each HF In S.Headers
If HF.Exists Then
MsgBox Choose(HF.Index, "Primary", "First Page", "Even Page") & " Header" & _
" in Section " & S.Index & _
" is " & IIf(HF.LinkToPrevious, "", "not ") & "linked to previous"
End If
Next
For Each HF In S.Footers
If HF.Exists Then
MsgBox Choose(HF.Index, "Primary", "First Page", "Even Page") & " Footer" & _
" in Section " & S.Index & _
" is " & IIf(HF.LinkToPrevious, "", "not ") & "linked to previous"
End If
Next
End If
Next S


Interesting to see some rather strange behaviour with Section 1 headers and footers but they are always, by definition, not linked to previous.

ronstarr
12-07-2007, 07:06 AM
Wow, that led me right to where I needed to be. Thank you. Pushing my luck, below is the code that I use to copy a line and text box out of a template and paste it into every non-linked-to-previous header in an existing document. Is there a better way to draw the line and create the text box on the fly rather than copying them from an existing template and pasting? [The line is an 11" vertical line positioned 0.7" from the left edge of the page] Again, thanks.

Sub PleadingPaper()
'go to the top of the document
Selection.HomeKey Unit:=wdStory
'open the pleading paper template and copy the line and text box
Documents.Add Template:= _
"C:\Program Files\Microsoft Office\Templates\xp\Pleading Paper Template.dot" _
, NewTemplate:=False, DocumentType:=0
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
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
Selection.WholeStory
Selection.Copy
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Close (wdDoNotSaveChanges)
'open the header on the current document and paste
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
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
Selection.Paste
Selection.TypeBackspace
'Do that for each remaining header in the document
Dim S, HF
For Each S In ActiveDocument.Sections
If S.Index > 1 Then
For Each HF In S.Headers
If HF.Exists Then
ActiveWindow.ActivePane.View.NextHeaderFooter
'MsgBox Choose(HF.Index, "Primary", "First Page", "Even Page") & " Header" & _
'" in Section " & S.Index & _
'" is " & IIf(HF.LinkToPrevious, "", "not ") & "linked to previous"
If HF.LinkToPrevious Then
Else
Selection.Paste
Selection.TypeBackspace
End If
End If
Next
End If
Next S
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

TonyJollans
12-07-2007, 07:12 AM
You've obviously recorded the basis of that code. It will be much easier and more efficient to work directly with the headers and footers rather than working with the views but I have to go out now so will post a little later.

Is there anything special about the text box that requires it to be copied from somewhere else - there doesn't seem to be about the line?

ronstarr
12-07-2007, 08:36 AM
Tony: Thanks for the quick reply. The text box sits vertically in the header over the line (text in front) and simply has the firm's name in it.

I could not figure out how to record either putting in the line or the text box, and don't know where to look to find code which can do that.

TonyJollans
12-07-2007, 09:28 AM
Is there any particular reason you need a TextBox just for the Firm's name?

ronstarr
12-07-2007, 11:04 AM
The only reason I have used a text box for the firm's name is that the text box rests overtop of the line, and its text is in front of the line. See attached.

I suspect from your comment that I don't need a textbox, but I need the text rotated and don't know how to otherwise do it.

I have gotten this far in so far as creating the line with code:
Set lineNew = ActiveDocument.Shapes.AddLine(50, 790, 50, 0)

but I can't get the line within the header itself (so that it repeats on every page).

ronstarr
12-07-2007, 02:47 PM
I think I got the code working. If you have any suggestions I am always open to them. Thanks for spending the time.

Sub PleadingPaper()
Dim lineNew As Shape, lineNew1 As Shape, newTextbox As Shape, newTextbox1 As Shape
'go to the top of the document
Selection.HomeKey Unit:=wdStory
'open the first header on the current document
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
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
'insert the line and text box into the first header
Set lineNew = ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddLine(50, 790, 50, 0)
Set newTextbox = ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddTextbox _
(Orientation:=msoTextOrientationUpward, _
Left:=45, Top:=308, Width:=20, Height:=180)
With newTextbox
.TextFrame.TextRange = "Foster, Swift, Collins & Smith, P.C./Attorneys At Law"
.TextFrame.TextRange.Font.Name = "GoudyOlSt BT"
.TextFrame.TextRange.Font.Size = 8
.Fill.Transparency = 0#
.Line.Visible = msoFalse
.LockAspectRatio = msoFalse
.TextFrame.MarginLeft = 0#
.TextFrame.MarginRight = 0#
.TextFrame.MarginTop = 0#
.TextFrame.MarginBottom = 0#
.ZOrder 4
.TextFrame.AutoSize = True
End With
'Insert the line and text box into each remaining header in the document
Dim S, HF
For Each S In ActiveDocument.Sections
If S.Index > 1 Then
For Each HF In S.Headers
If HF.Exists Then
ActiveWindow.ActivePane.View.NextHeaderFooter
If HF.LinkToPrevious Then
Else
Set lineNew1 = ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddLine(50, 790, 50, 0)
Set newTextbox = ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddTextbox _
(Orientation:=msoTextOrientationUpward, _
Left:=45, Top:=308, Width:=20, Height:=180)
With newTextbox
.TextFrame.TextRange = "LawFirm Name, P.C./Attorneys At Law"
.TextFrame.TextRange.Font.Name = "GoudyOlSt BT"
.TextFrame.TextRange.Font.Size = 8
.Fill.Transparency = 0#
.Line.Visible = msoFalse
.LockAspectRatio = msoFalse
.TextFrame.MarginLeft = 0#
.TextFrame.MarginRight = 0#
.TextFrame.MarginTop = 0#
.TextFrame.MarginBottom = 0#
.ZOrder 4
.TextFrame.AutoSize = True
End With
End If
End If
Next
End If
Next S
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

TonyJollans
12-07-2007, 05:02 PM
No attachment, I'm afraid - maybe because you don't have enough posts - try again, it may work.

You're on the right track. You just need to add it to the Header Range instead of the main body of the Document. This should work ...

Sub Stuff()
Dim S As Section
Dim HF As HeaderFooter
For Each S In ActiveDocument.Sections
For Each HF In S.Headers
If HF.Exists Then
If S.Index = 1 Or HF.LinkToPrevious = False Then
With HF.Shapes.AddLine(0, 0, 0, 0, HF.Range)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = InchesToPoints(0.7)
.Top = 0
.Height = InchesToPoints(11)
.Width = 0
.Line.Weight = 3
End With
With HF.Shapes.AddTextbox(msoTextOrientationVertical, _
0, 0, 0, 0, HF.Range)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = InchesToPoints(0.5)
.Top = 0
.Height = InchesToPoints(1.1)
.Width = InchesToPoints(0.4)
.Line.Weight = 3
.TextFrame.TextRange.Text = "Word Articles"
End With
End If
End If
Next HF, S
End Sub

You may have to adjust the position and size of the textbox but do come back if you have any problem.

TonyJollans
12-07-2007, 05:11 PM
Sorry - i was away from the PC and came back and posted and didn't see that you had posted meanwhile. This uses your size and position for the textbox - I don't have the Font to know what it looks like. I suspect you have guessed at the numbers - which are in points (72 points = 1 inch) - you can use InchesToPoints as i have done for the line if you know the values you require in inches

Sub Stuff()
Dim S As Section
Dim HF As HeaderFooter
For Each S In ActiveDocument.Sections
For Each HF In S.Headers
If HF.Exists Then
If S.Index = 1 Or HF.LinkToPrevious = False Then
With HF.Shapes.AddLine(0, 0, 0, 0, HF.Range)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = InchesToPoints(0.7)
.Top = 0
.Height = InchesToPoints(11)
.Width = 0
.Line.Weight = 3
End With
With HF.Shapes.AddTextbox(msoTextOrientationVertical, _
0, 0, 0, 0, HF.Range)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = 45
.Top = 308
.Height = 180
.Width = 20
.Line.Weight = 3
.TextFrame.TextRange = "Foster, Swift, Collins & Smith, P.C./Attorneys At Law"
.TextFrame.TextRange.Font.Name = "GoudyOlSt BT"
.TextFrame.TextRange.Font.Size = 8
End With
End If
End If
Next HF
Next S
End Sub