title: How to check orientation of each consecutive section?
body: <p>I am working on a macro that would plot through currently opened document sections one by one, check whether they are portrait or landscape, and set their margins (incl. header and footer) to given dimensions (which are different depending on the page orientation).</p>
  
  <p>How do I detect the page orientation of each section and make it the current "selection" or put the cursor on its beginning, so the next line could set its margins and skip to the next section?</p>
  
  <p>This is what I got so far:</p>
  
  <pre><code>Sub Margins()
      Dim nOriginalPagination     As Integer
      Dim objSection              As Section
      Dim nPaperSize              As Integer
      Dim ContinueOn              As Boolean
  
      ContinueOn = False
      nNumSects = ActiveDocument.Sections.Count
  
      ActiveWindow.View.Type = wdPageView
  
      If ActiveWindow.View.SeekView &lt;&gt; wdSeekMainDocument Then
          ActiveWindow.View.SeekView = wdSeekMainDocument
      End If
  
      Selection.HomeKey wdStory, wdMove
  
      For Each objSection In objDocument.Sections
          iSecNum = Selection.Information(wdActiveEndSectionNumber)
          With objSection.PageSetup
              nPaperSize = PAPERLETTER    
          End With
      Next
  
      For Each objSection In objDocument.Sections
          iSecNum = Selection.Information(wdActiveEndSectionNumber)
          With objSection.PageSetup
              'Set the margins, depending on the page orientation
              If .Orientation = wdOrientPortrait Then
                  .TopMargin = CentimetersToPoints(2.23)
                  .BottomMargin = CentimetersToPoints(2.21)
                  .LeftMargin = CentimetersToPoints(3.17)
                  .RightMargin = CentimetersToPoints(3.17)
                  .HeaderDistance = CentimetersToPoints(0.96)
                  .FooterDistance = CentimetersToPoints(0.94)
              Else
                  .TopMargin = CentimetersToPoints(3.17)
                  .BottomMargin = CentimetersToPoints(3.17)
                  .LeftMargin = CentimetersToPoints(2.21)
                  .RightMargin = CentimetersToPoints(2.23)
                  .HeaderDistance = CentimetersToPoints(1.9)
                  .FooterDistance = CentimetersToPoints(1.9)
              End If
          End With
  
          Application.ScreenUpdating = True
          Options.Pagination = nOriginalPagination
  
          Selection.GoTo what:=wdGoToSection, Which:=wdGoToNext
  
      Next
  
  End Sub
  </code></pre>
  
  <p>Error says I am missing as object.</p>