Hi,
I’m trying to create a macro that checks each section of a document. If the section is portrait, I set the footer tab to 6 inches. If the section is landscape, I set the footer tab to 9 inches. I keep getting an object variable-related message, but my attempts to fix it have failed.
The following post (100219) was helpful, but I’m still having trouble:
http://www.wopr.com/cgi-bin/w3t/showthread…ew=&sb=&o=&vc=1
Thanks,
Bob
**************************************************************************************************
Sub FixSectionOrientation()
Dim oSec As Section
Dim oHead As HeaderFooter
Dim oFoot As HeaderFooter
Dim oRng As Range
Dim counter1 As Long
Dim orient As Long
‘Go to first footer
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, count:=1, Name:=””
Selection.Find.ClearFormatting
With Selection.Find
.Text = “”
.Replacement.Text = “”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
‘Show footer
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 = wdSeekCurrentPageFooter
‘Set tab to 6 inches in first footer
Selection.EndKey Unit:=wdLine
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(6), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
‘Loop through sections, starting with Section 2
‘If section is portrait, set tab to 6 inches
‘If section is landscape, set tab to 9 inches
For counter1 = 2 To ActiveDocument.Sections.count
‘Go to section
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, count:=counter1, Name:=””
Selection.Find.ClearFormatting
With Selection.Find
.Text = “”
.Replacement.Text = “”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
‘Show footer
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 = wdSeekCurrentPageFooter
‘If section is portrait, set tab to 6 inches
If oSec.PageSetup.Orientation = 0 Then
Selection.EndKey Unit:=wdLine
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(6), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
End If
‘If section is landscape, set tab to 9 inches
If oSec.PageSetup.Orientation = 1 Then
Selection.EndKey Unit:=wdLine
Selection.ParagraphFormat.TabStops.ClearAll
ActiveDocument.DefaultTabStop = InchesToPoints(0.5)
Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(9), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
End If
Next counter1
End Sub