I'm going nuts trying to figure out how to add a new row at the end of the table. Specifically, I add new entries daily to my table, and want to automate data entry via AHK input boxes.
I know the VBA to add a new row is
Code: Select all
WordDoc.Tables.(1).Rows.Add
Code: Select all
WordDoc.Tables(1).Rows.count
Code: Select all
ActiveDocument.Tables(1).Rows.Last.Cells.Delete
Code: Select all
ActiveDocument := ComObjActive("Word.Application").ActiveDocument
intCount := 1
tblNew := ActiveDocument.Tables(1)
ActiveDocument.Tables(1).Rows.Last.Cells.Add
And this forum discussion from 2013 adds rows (as well as unhelpful text) to the BEGINNING of the table: https://www.autohotkey.com/board/topic/98894-entering-a-row-into-a-ms-word-table-with-the-help-of-ahk/:
Code: Select all
ActiveDocument := ComObjActive("Word.Application").ActiveDocument
intCount := 1
tblNew := ActiveDocument.Tables(1)
rowNew := tblNew.Rows.Add( tblNew.Rows(1) )
Cells := rowNew.Cells
Loop % Cells.Count {
celTable := Cells.Item(A_Index)
celTable.Range.InsertAfter( "Cell " . intCount )
intCount := intCount + 1
}