word automation table

#vb_ref: Function Add(Range As Range, NumRows As Long, NumColumns As Long, [DefaultTableBehavior], [AutoFitBehavior]) As Table

def add_table(doc, range, rows, cols)

doc.Tables.Add({‘Range’ => range, ‘NumRows’ => rows, ‘NumColumns’ => cols})

# doc.Tables.Add(range, rows, cols)



#vb_ref: Function Cell(Row As Long, Column As Long) As Cell

def set_table_cell(table, i, j, text)

table.Cell(i, j).Range.Text = text




word automation range

The Range object represents a contiguous area in a document, and is defined by a starting character position and an ending character position.

Ranges can be obtained in many ways. Many Word objects, like Sentence and Paragraph, have a Range property that contains an object reference to a Range object for the original object.

sel_range = word.Selection.Range

p_range = doc.Paragraphs(3).Range


word object model overview

Automating word with ruby: the range object

Automating Microsoft Word