<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG/> </o:OfficeDocumentSettings> </xml><![endif]--> GOAL:
Linking SharePoint to Excel, so that Excel will contain pivots. Multiple SharePoint tables have been linked to individual sheets in Excel. A macro was written to consolidate the tables into another “MASTER” sheet, from which the data will be used for the pivot. A macro was written to create the pivots. All macros have been linked to a button on a blank sheet so that multiple users will be able to refresh the tables then create the pivots (following the creation of the MASTER sheet).
WHEN IT WORKS:
When the file is opened the first time, the macro runs correctly (because the name of the MASTER table hasn't changed, yet).
PROBLEM:
Each time the tables are consolidated into the MASTER sheet, the MASTER sheet TABLE name changes (from say "Table_1" to "Table_2"), preventing the pivots from being created. In VBA, the MASTER TABLE name is located following "SourceData:=" (see code below).
QUESTION:
How might I reference the table without referencing the MASTER TABLE name, which constantly changes?
What I’d like “SourceData:=” to reflect is (and I’m making this up, of course)
Linking SharePoint to Excel, so that Excel will contain pivots. Multiple SharePoint tables have been linked to individual sheets in Excel. A macro was written to consolidate the tables into another “MASTER” sheet, from which the data will be used for the pivot. A macro was written to create the pivots. All macros have been linked to a button on a blank sheet so that multiple users will be able to refresh the tables then create the pivots (following the creation of the MASTER sheet).
WHEN IT WORKS:
When the file is opened the first time, the macro runs correctly (because the name of the MASTER table hasn't changed, yet).
PROBLEM:
Each time the tables are consolidated into the MASTER sheet, the MASTER sheet TABLE name changes (from say "Table_1" to "Table_2"), preventing the pivots from being created. In VBA, the MASTER TABLE name is located following "SourceData:=" (see code below).
QUESTION:
How might I reference the table without referencing the MASTER TABLE name, which constantly changes?
Code:
'Create Pivot
ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, _
SourceData:="Table_1", _
Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:=Worksheets("MASTER").Range("A1"), _
TableName:="PivotTable2", _
DefaultVersion:=xlPivotTableVersion12
What I’d like “SourceData:=” to reflect is (and I’m making this up, of course)
Code:
SourceData:=(INPUT HERE CODING SO THAT NO MATTER WHAT THE TABLE NAME IS THIS CODE WILL WORK)