Consulting

Results 1 to 3 of 3

Thread: Chaos in Headers/Footers

  1. #1
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location

    Chaos in Headers/Footers

    Is there any reason why a line shape in the header of a page would get deleted when I insert a table in the footer of the same page?

    I put the shape into the header like so:
            Set ShpLine = ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Shapes.AddLine(72, 60, 568, 60)
            With ShpLine
                .Line.ForeColor.RGB = RGB(0, 0, 0) 'Black line
                .Line.Weight = 3
            End With
    I use the following to insert a table into the footer and PRESTO! the header shape (line) disappears:
                Set myTable = ActiveDocument.Tables.Add(Range:=ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Paragraphs(ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Paragraphs.Count).Range, numrows:=3, numcolumns:=3, AutoFitBehavior:=wdAutoFitFixed)

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    Because you are killing the shape anchor when you insert the table in the same range.

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim ShpLine
    Dim oRng As Range
    Dim myTable
      Set ShpLine = ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Shapes.AddLine(72, 60, 568, 60)
      With ShpLine
          .Line.ForeColor.RGB = RGB(0, 0, 0) 'Black line
          .Line.Weight = 3
      End With
      Set oRng = ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Paragraphs(ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Paragraphs.Count).Range
      oRng.Collapse wdCollapseStart
      Set myTable = ActiveDocument.Tables.Add(oRng, 3, 3, wdAutoFitFixed)
    lbl_Exit:
      Exit Sub
    End Sub
    When you post code, please include variable declarations.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Contributor
    Joined
    Aug 2012
    Posts
    120
    Location
    Awesome! Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •