'Inserting a row in a Word table from Excel

I have an Excel spreadsheet that contains information to be put into a Word invoice template. I am able to populate header details, such as client name, address, etc.

I need to add the number of invoice lines so that I can populate the body of the invoice.

Dim wdApp As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
    Set wdApp = CreateObject("Word.Application")
End If
wdApp.Visible = True
On Error GoTo 0
wdDoc = wdApp.Documents.Add(invoiceTemplate)
invoiceRowsToAdd = WorksheetFunction.CountIfs(tblRegister.DataBodyRange.Columns(1), client) - 1
If invoiceRowsToAdd > 0 Then
    wdApp.ActiveDocument.Tables(2).Cell(3, 1).Range.Rows.Select
    Selection.InsertRowsBelow invoiceRowsToAdd
End If

If I check the Word document, the row is being selected, however it doesn't add any rows.
I confirmed that the invoiceRowsToAdd variable is returning the correct value.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source