Connections Methods

Name Returns Parameters Description

Add Workbook Name As String, Returns a

Connection Description As String, WorkbookConnection

ConnectionString object, via a connection

As Variant, string defining a

CommandText As Variant, connection to an lCmdtype external data source

Filename As String, Returns a

WorkbookConnection object, via an Office Data Connection (.odc) file, a Offline Cube file (.cub), or any other file that defines an external data source

Connections Example

This example adds a connection to a local cube file and then creates a PivotTable.

AddFromFile Workbook

Connection

Sub Create_LocalCube_PivotTable()

'Add a connection to the local cube file

ActiveWorkbook.Connections.AddFromFile "C:\MyCustomCube.cub" 'Create a Pivot Cache and Pivot Table

ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, _ SourceData:=ActiveWorkbook.Connections("MyCustomCube")).CreatePivotTable TableDestination:=Range("A1"), TableName:="MyPivot" End Sub

0 0

Post a comment