You are on page 1of 1

' Listing 1: Macro That Uses the Model Object

Sub AddDateTableToModel()
On Error GoTo The_Error
' Refresh the existing model.
ActiveWorkbook.Model.Refresh
' Add a connection to the Data Model.
Dim oWorkbookConn As Excel.WorkbookConnection
Set oWorkbookConn = ActiveWorkbook.Connections.Add2( _
Name:="DateTable", Description:="Date Table from " & _
"www.UnderstandingTheUSDebt.com", ConnectionString:= _
Array("DATAFEED;Data Source=http://www.understanding" &
"usdebt.com/odata/WcfDataSvcUSDebtv2.svc/;Namespaces" &
"to Include=*;Max Received Message Size=439804651110" &
"4; Integrated Security=SSPI;Keep Alive=true;Persist" &
" Security Info=false;Service Document Url=http://" & _
"www.understandingtheusdebt.com/odata/WcfDataSvcUS" & _
"Debtv2.svc/ "), CommandText:=Array("DateTbl"), _
lCmdType:=6, CreateModelConnection:=True, _
ImportRelationships:=False)
' Add a relationship between the Date and GDP tables.
With ActiveWorkbook.Model
.ModelRelationships.Add .ModelTables("GDP"). _
ModelTableColumns("Date"), _
.ModelTables("DateTbl").ModelTableColumns("Date")
End With
Exit Sub
The_Error:
MsgBox "Error Encountered: " & Err.Description & _
vbTab & Err.Source, vbCritical, "Error."
End Sub

_
_
_
_

You might also like