<< Click to Display Table of Contents >> Tables (collection) |
Access paths:
▪Application à Documents à Item à Tables
▪Application à ActiveDocument à Tables
1 Description
Tables is a collection of all tables in a document. The individual elements of this collection are of the type Table.
2 Access to the collection
Each open document has exactly one instance of the Tables collection. It is accessed through Document.Tables:
' Display the number of tables in the active document
MsgBox tm.ActiveDocument.Tables.Count
3 Properties, objects, collections and methods
Properties:
▪Count R/O
Objects:
▪Item → Table (default object)
▪Application → Application
▪Parent → Document
Methods:
▪Add
Count (property, R/O)
Data type: Long
Returns the number of Table objects in the document – in other words: the number of the tables in the document.
Item (pointer to object)
Data type: Object
Returns an individual Table object, i.e. an individual table.
Which Table object you get depends on the parameter that you pass to Item. You can specify either the numeric index or the name of the desired table. Examples:
' Display the number of rows in the first table
MsgBox tm.Tables.Item(1).Rows.Count
' Display the number of rows in the table names "Table1"
MsgBox tm.Tables.Item("Table1").Rows.Count
Application (pointer to object)
Data type: Object
Returns the Application object.
Parent (pointer to object)
Data type: Object
Returns the parent object, i.e. an object of the type Document.
Add (method)
Add a new table to the document at the current selection.
Syntax:
Add NumRows, NumColumns
Parameters:
NumRows (type: Long) defines the number of rows for the new table. If you specify a value of 0 or less, the default value 3 will be used. |
NumColumns (type: Long) defines the number of columns for the new table. If you specify a value of 0 or less, the default value 3 will be used. |
Return type:
Object (a Table object which represents the new table) |
Examples:
' Add a 3*3 table to the document
tm.ActiveDocument.Tables.Add 3, 3
' The same, but working with the table as an object
Dim newTable as Object
Set newTable = tm.ActiveDocument.Tables.Add(3, 3)
MsgBox newTable.Rows.Count ' Display the number of table rows