title: Delete last section in Word VBA without the previous heading getting overwritten
body: <p>I have the following code that I found when googleing on the problem. The problem with this code is that it overwrites the next-to-last section header (and footer though I only need the header preserved) to that of the last section, which is the default (strange) behavior of Word.</p>
  
  <p>Is there a workaround to this in VBA?</p>
  
  <p>Here is the code that has the inherent fault:</p>
  
  <pre><code>Sub DeleteLastSection()
  'Deletes last section of a document including
  'the section break
  Dim doc As Document
  Dim rng As Range
  Dim ctr As Integer
  Set doc = ActiveDocument
  ctr = doc.Sections.Count
  Set rng = doc.Sections(ctr).Range
  Dim myheader As HeaderFooter
  If ctr &gt; 1 Then
      With rng
          .Select
          .MoveStart Unit:=wdCharacter, Count:=-1
          .Delete
      End With
  End If
  End Sub
  </code></pre>
  
  <p><strong>Note:</strong> The entire range of the last section is being deleted by the code and that is the required behavior. The inherent problem in the default behavior of Word is what I needed a workaround for in VBA code. One can found complex manual procedures to avoid it, but I needed a simple approach in code.</p>