Class ModelTable (Excel VBA)

The class ModelTable represents a table in the data model.

Item

To use a ModelTable class variable it first needs to be instantiated, for example

Dim mdlt as ModelTable
Set mdlt = ActiveWorkbook.Model.ModelTables(Index:=1)

The following procedures can be used to set variables of type ModelTable: ModelMeasure.AssociatedTable, ModelRelationship.ForeignKeyTable, ModelRelationship.PrimaryKeyTable and ModelTables.Item.

For Each

Here is an example of processing the ModelTable items in a collection.

Dim mdlt As ModelTable
For Each mdlt In ActiveWorkbook.Model.ModelTables
	
Next mdlt

ModelTableColumns

Collection of ModelTableColumns objects that make up the ModelTable.

Dim mtcsModelTableColumns As ModelTableColumns
Set mtcsModelTableColumns = ActiveWorkbook.Model.ModelTables(1).ModelTableColumns

Name

Returns a String value that represents the name of the object.

Dim strName As String
strName = ActiveWorkbook.Model.ModelTables(1).Name

RecordCount

Returns the total row count for the model table.

Dim lngRecordCount As Long
lngRecordCount = ActiveWorkbook.Model.ModelTables(1).RecordCount

Refresh

Refreshes the model table source connections.

ActiveWorkbook.Model.ModelTables(1).Refresh

SourceName

Name of the data source for the table. If the table has no data source, the call will generate a run-time error.

Dim strSourceName As String
strSourceName = ActiveWorkbook.Model.ModelTables(1).SourceName

SourceWorkbookConnection

Returns the Workbook Connection from which the model table originated.

Dim wbconSourceWorkbookConnection As WorkbookConnection
Set wbconSourceWorkbookConnection = ActiveWorkbook.Model.ModelTables(1).SourceWorkbookConnection

ModelTables.Count

Returns a Long value that represents the number of ModelTable objects in a ModelTables collection.

Dim lngCount As Long
lngCount = ActiveWorkbook.Model.ModelTables.Count

ModelTables.Item

Returns a single object from the ModelTables collection.

Item (Index)

Index: The index number or name of the object.

Dim mdlt As ModelTable
Set mdlt = ActiveWorkbook.Model.ModelTables(Index:=1)