Adding table in Word Doc over writes previous lines

Please excuse what is probably a simple answer - I am very new at VBA. I am using VBA in Excel and attempting to write to a Word document. The document is to have a few lines of text followed by a 6x6 table. When I do a:

Set tableNew = .Tables.Add(.Range, 6, 6)

it overwrites the previous lines I wrote. I'm sure there's a way to place this table in the appropriate spot in the document, but I've been unable to find any documentation on this.

Can you offer any help with this

Thanks, kgkidd



Answer this question

Adding table in Word Doc over writes previous lines

  • craigman

    This was my first question using this forum.  Doesn't seem to be much assistance here - not a single response.  Unfortunately I still haven't found the answer.  Possibly the question was more difficult that I had expected.  Thanks anyway . . .
  • Daudi

    The VBA help on the Add method of the Tables object says, "the table replaces the range, if the range isn't collapsed".

    Sub AddTable()
    Dim rng As Range
    Dim tbl As Table
    'set rng to first paragraph
    Set rng = ActiveDocument.Range(Start:=ActiveDocument.Paragraphs(1).Range.Start, _
    End:=ActiveDocument.Paragraphs(1).Range.End)

    rng.Collapse direction:=wdCollapseEnd
    Set tbl = ActiveDocument.Tables.Add(rng, 6, 6) 'insert table after paragraph
    End Sub


  • Adding table in Word Doc over writes previous lines