Dhay February 2016

autohotkey word com obj add multiple tables

I try to create a word document with two tables with Autohotkey. I could successfully add one table and type some text. Now I try to create another table in the same document below old table.

oWord := ComObjCreate("Word.Application")       ; create MS Word object
Document := oWord.Documents.Add             ; create new document
oWord.Visible := 1                  ; Make winword visible
range := oWord.ActiveDocument.Range(0, 0)       ; Set Range
oWord.ActiveDocument.tables.Add(range,1,2)      ; Add table in range
oWord.Selection.Tables(1).Style := "Table Grid"     ; set style
oWord.Selection.Tables(1).Cell(1,2).Range.Select    ; select a cell
oWord.Selection.TypeText("Hi hi")           ; type a text in selected cell
oWord.Selection.EndKey                  ; from here I couldn't able to create a new table
oWord.Selection.TypeParagraph
range := oWord.ActiveDocument.Range(0, 0) 
oWord.ActiveDocument.tables.Add(range,10,5)
oWord.Selection.Tables(1).Style := "Table Grid"
oWord.Selection.Tables(1).Cell(1,3).Range.Select    ; get error 0x800A1735 and it mentions 'Cell' The requested member of the collection does not exist
;oWord.Selection.TypeText("Hi di")
oWord.Quit

What wrong I am doing here?

Answers


Dhay February 2016

Thank you for everyone for trying to give solution for this question. I could able to figure out one idea two hours after posting this question. I had to add

oWord.Selection.MoveDown(5,1)

before

oWord.Selection.EndKey

and modify

oWord.ActiveDocument.tables.Add(oWord.Selection.Range,5,5)

instead

oWord.ActiveDocument.tables.Add(range,5,5)

and removed second

range := oWord.ActiveDocument.Range(0, 0)

Post Status

Asked in February 2016
Viewed 3,765 times
Voted 9
Answered 1 times

Search




Leave an answer