Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro needed: How to search then change page orientation

Status
Not open for further replies.

Imagineer

New member
Mar 28, 2000
43
US
Hello,
I'm unix hand that is a novice at WORD macros/programming so I'm having problems with this code.
We have some text files that are being combined and then brought into word for document type formatting, etc. In the original text file, the authors put [LANDSCAPE:ON] and [LANDSCAPE:OFF]when they wanted to change page orientation. I'm bringing all of these into word. I recorded a macro for one instance then tried to edit it to loop. Below is the code. It seems to have two problems. First, it only finds one instance. Second, it inserts the orientation change at the position from which the macro was run, not at the "found" position.

Sub FormatOutput()
'
' FormatOutput Macro
' Macro recorded 6/12/02
'
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.Text = " "

Do While .Execute(FindText:="[Landscape:On]", ReplaceWith:=" ", Forward:=True) = True
Selection.InsertBreak Type:=wdSectionBreakContinuous
With Selection.PageSetup
.Orientation = wdOrientLandscape
.DifferentFirstPageHeaderFooter = False
End With
Loop
End With
With ActiveDocument.Content.Find
Do While .Execute(FindText:="[Landscape:OFF]", ReplaceWith:=" ", Forward:=True) = True
Selection.InsertBreak Type:=wdSectionBreakContinuous
With Selection.PageSetup
.Orientation = wdOrientPortrait
.DifferentFirstPageHeaderFooter = False
End With
Loop
End With

End Sub


TIA, Imagineer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top