lkpederson
05-11-2015, 07:10 AM
Macro below is a modification of one Paul Edstein (macropod) posted. I'm trying to get the text "page left intentionally blank" to center on "blank page".
Sub InsertBlankPageField()
Dim Sctn As Section, Rng As Range
' see if there are any field codes first. If not, exit. If so, see if the
' field codes have the IF in them, trying to find code for adding page for
' documents ending with odd number of pages.
If ActiveDocument.Fields.Count = 0 Then
With ActiveDocument
For Each Sctn In .Sections
With Sctn.Range
' move to end of document, set rng at the end
' then collapse range to after end of last word
Selection.EndKey Unit:=wdStory
Set Rng = .Characters.Last.Previous
Rng.Collapse wdCollapseEnd
.Fields.Add Range:=Rng, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="IF = 1"
Set Rng = .Fields(1).Code
Rng.Start = Rng.Start + 3
Rng.Collapse wdCollapseStart
.Fields.Add Range:=Rng, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="=MOD(,2)"
Set Rng = .Fields(2).Code
Rng.Start = Rng.Start + 6
Rng.Collapse wdCollapseStart
.Fields.Add Range:=Rng, Type:=wdFieldPage, _
PreserveFormatting:=False
Set Rng = .Fields(1).Code
Rng.End = Rng.End
Rng.Collapse wdCollapseEnd
.Fields.Add Range:=Rng, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="QUOTE 12" & Chr(34) & Chr(13) & _
Chr(13) & "This page intentionally left blank." & Chr(34)
' Set Rng = .Fields(4).Code
' Rng.Start = Rng.Start + 9
' Rng.Collapse wdCollapseStart
' .Fields.Add Range:=Rng, Type:=wdFieldAdvance, Text:="\d 300"
.Fields.Update
End With
Next
End With
End Sub
I've tried various and sundry combinations and have had no luck. I have found that whenever I do use wdFieldAdvance, the text won't show up on the page.
Any takers?
/TIA
Lise
Sub InsertBlankPageField()
Dim Sctn As Section, Rng As Range
' see if there are any field codes first. If not, exit. If so, see if the
' field codes have the IF in them, trying to find code for adding page for
' documents ending with odd number of pages.
If ActiveDocument.Fields.Count = 0 Then
With ActiveDocument
For Each Sctn In .Sections
With Sctn.Range
' move to end of document, set rng at the end
' then collapse range to after end of last word
Selection.EndKey Unit:=wdStory
Set Rng = .Characters.Last.Previous
Rng.Collapse wdCollapseEnd
.Fields.Add Range:=Rng, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="IF = 1"
Set Rng = .Fields(1).Code
Rng.Start = Rng.Start + 3
Rng.Collapse wdCollapseStart
.Fields.Add Range:=Rng, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="=MOD(,2)"
Set Rng = .Fields(2).Code
Rng.Start = Rng.Start + 6
Rng.Collapse wdCollapseStart
.Fields.Add Range:=Rng, Type:=wdFieldPage, _
PreserveFormatting:=False
Set Rng = .Fields(1).Code
Rng.End = Rng.End
Rng.Collapse wdCollapseEnd
.Fields.Add Range:=Rng, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="QUOTE 12" & Chr(34) & Chr(13) & _
Chr(13) & "This page intentionally left blank." & Chr(34)
' Set Rng = .Fields(4).Code
' Rng.Start = Rng.Start + 9
' Rng.Collapse wdCollapseStart
' .Fields.Add Range:=Rng, Type:=wdFieldAdvance, Text:="\d 300"
.Fields.Update
End With
Next
End With
End Sub
I've tried various and sundry combinations and have had no luck. I have found that whenever I do use wdFieldAdvance, the text won't show up on the page.
Any takers?
/TIA
Lise