locked
How to AddTextBox onto Footer area in Office Word 2010? RRS feed

  • Question

  • I have been researching for hours and could not find any workaround to this VBA macro issue.

    I basically want to AddTextBox close the footer area. I have the same code running perfectly fine in Word 2007, but not in Word 2010.

    Please look at the snippet code:

    Set oRange = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range

    Set textbox = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Shapes.AddTextbox(msoTextOrientationHorizontal, 0, 0, 100, 15, oRange)

    textbox.Text = "Test"

     

    Whenever I run the macro on word 2010, the text box get added on to the Header area. In Word 07, text box appears correctly over the footer area and also consider the left indentation.

     

    Any workaround or suggestion? Thanks in advance

     

    Monday, August 8, 2011 11:53 AM

Answers

  • This should do it:

    Sub footerTextBox()
      Dim rng As Word.Range
      Dim shp As Word.Shape
      Dim doc As Word.Document
      Dim top As Single
      Dim lft As Single
      
      Set doc = Word.ActiveDocument
    
      Set rng = doc.Sections(1).Footers(wdHeaderFooterPrimary).Range
      top = rng.Information(wdVerticalPositionRelativeToPage)
      lft = rng.Information(wdHorizontalPositionRelativeToPage)
      
      Set shp = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, lft, top, 100, 15, rng)
      shp.WrapFormat.Type = wdWrapInline
    
    End Sub
    
    

     


    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by Su L Tuesday, August 9, 2011 4:03 AM
    Tuesday, August 9, 2011 3:30 AM