Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VBA for Word, how do I create a range of table cells?

I'm trying to learn how to handle Range objects in Word VBA with regards to MS Word tables.

Using the Range object help, it would seem I can create a range of cells as long as the cells are contiguous, however I cannot seem to get the syntax for specifying the Start and End points of the range using cells.

For example:

Set rngCells = myTable.Range(Start:=<cell>, End:=<cell>)

I'm not sure what to put in for to indicate the cell to start or the cell to end with. Can someone give me a clue? :)

Edit: I've already created the table from scratch -- I'm trying to use a range of cells for some of the rows in the middle to apply formatting to them. In particular, I'm trying to see if this can be done without using Selection.

like image 429
romandas Avatar asked Sep 25 '09 17:09

romandas


1 Answers

I found the answer I was looking for:

Set myCells = ActiveDocument.Range(Start:=ActiveDocument.Tables(1).Cell(1, 1).Range.Start, _
             End:=ActiveDocument.Tables(1).Cell(1, 1).Range.End)

I did not realize the Range object was from the Document object, not the Table object.

like image 159
romandas Avatar answered Sep 30 '22 23:09

romandas