none
Update data in the header footer of a word document.

    Question

  • I use the following code to detect a table within the header of word 2010 document.

       

    internal void WalkHeaders(ref Word.Document aDoc)
        {
          Word.Range rng;
          foreach (Word.Section sec in aDoc.Sections)

            {
             foreach (Word.HeaderFooter hfRng in sec.Headers)
              {
                 rng = hfRng.Range;
              foreach (Word.Table t in rng.Tables)
              {
                string x =  t.Cell(1, 1).Range.Text;
              }
            }
          }
        }

    It does not find a table is imbedded within a textbox. I need to manipulate text that is 1 inch from the top of the page and .2 inch from the left edge of the page for a barcode.

    How can I insert a table at this position?  Is it possible to locate the table that is imbedded in the textbox?

     


    Leonard Swarczinski Software Developer Postal Center International

    Monday, July 22, 2013 4:16 PM

Answers

  • Hi Leonard,

    Textboxes are part of the Shapes collection so you have to look at those separately. Here is VBA code that does that.

    Sub findHeaderTable()
        Dim doc As Word.Document, rng As Word.Range, shp As Word.Shape
        Dim hdft As Word.HeaderFooter, sec As Word.Section
        
        Set doc = ActiveDocument
        For Each sec In doc.Sections
            For Each hdft In sec.Headers
                For Each shp In hdft.Shapes
                    If shp.Type = msoTextBox Then
                        If shp.TextFrame.TextRange.Tables.Count > 0 Then
                            Debug.Print "Now do something with the table"
                        End If
                    End If
                Next
            Next
        Next
    End Sub
    


    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, July 22, 2013 7:10 PM

All replies

  • Hi Leonard,

    Textboxes are part of the Shapes collection so you have to look at those separately. Here is VBA code that does that.

    Sub findHeaderTable()
        Dim doc As Word.Document, rng As Word.Range, shp As Word.Shape
        Dim hdft As Word.HeaderFooter, sec As Word.Section
        
        Set doc = ActiveDocument
        For Each sec In doc.Sections
            For Each hdft In sec.Headers
                For Each shp In hdft.Shapes
                    If shp.Type = msoTextBox Then
                        If shp.TextFrame.TextRange.Tables.Count > 0 Then
                            Debug.Print "Now do something with the table"
                        End If
                    End If
                Next
            Next
        Next
    End Sub
    


    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, July 22, 2013 7:10 PM
  • This solved my issue. Thank You.


    Leonard Swarczinski Software Developer Postal Center International

    Wednesday, July 24, 2013 6:50 PM