Having difficulty and would appreciate some insight...
Objective is to use Excel vba to create pivot table that is based on a Sql Server 2005 cube.
Upon running the vba code, I receive a "subscript is out of range error" and the follwing part of the code is highlighted
Workbooks("Book2").Connections.Add "SSAS_PROD EduSales Cube EduSales", "", _
"OLEDB;Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=True;Data Source=SSAS_PROD;Initial Catalog=EduSales Cube" _
, Array("EduSales"), 1
Would like to save the code as part of a Excel macro-enabled workbook and then going forward just open the workbook and run the code.
did try to save as part of the personal workbook but was not allowed due to a error with something like "personal workbook must remain open..."
What modifications are needed so that I can run the code using the Macro-enabled workbook and be prompted for a filename and then have the Excel workbook stored at C:\Analysis?
Thanks in advance for some insight.
Objective is to use Excel vba to create pivot table that is based on a Sql Server 2005 cube.
Upon running the vba code, I receive a "subscript is out of range error" and the follwing part of the code is highlighted
Workbooks("Book2").Connections.Add "SSAS_PROD EduSales Cube EduSales", "", _
"OLEDB;Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=True;Data Source=SSAS_PROD;Initial Catalog=EduSales Cube" _
, Array("EduSales"), 1
Would like to save the code as part of a Excel macro-enabled workbook and then going forward just open the workbook and run the code.
did try to save as part of the personal workbook but was not allowed due to a error with something like "personal workbook must remain open..."
What modifications are needed so that I can run the code using the Macro-enabled workbook and be prompted for a filename and then have the Excel workbook stored at C:\Analysis?
Thanks in advance for some insight.
Code:
Sub mcrEduSalesCube()
'
' mcrEduSalesCube Macro
' Create EduSales Cube
'
' Keyboard Shortcut: Ctrl+Shift+M
'
Workbooks("Book2").Connections.Add "SSAS_PROD EduSales Cube EduSales", "", _
"OLEDB;Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=True;Data Source=SSAS_PROD;Initial Catalog=EduSales Cube" _
, Array("EduSales"), 1
ActiveWorkbook.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
ActiveWorkbook.Connections("SSAS_PROD EduSales Cube EduSales"), Version:= _
xlPivotTableVersion12).CreatePivotTable TableDestination:="Sheet1!R1C1", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12
Cells(1, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").CubeFields("[Measures].[Paid Amt]")
With ActiveSheet.PivotTables("PivotTable1").CubeFields("[Date].[Month]")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").CubeFields( _
"[Product].[Market Desc]")
.Orientation = xlPageField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Product].[Market Desc].[Market Desc]").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Product].[Market Desc].[Market Desc]").CurrentPageName = _
"[Product].[Market Desc].&[Wash - Seattle]"
With ActiveSheet.PivotTables("PivotTable1").CubeFields( _
"[Service Category].[Svc Desc]")
.Orientation = xlPageField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Service Category].[Svc Desc].[Svc Desc]"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields( _
"[Service Category].[Svc Desc].[Svc Desc]"). _
CurrentPageName = _
"[Service Category].[Svc Desc].&[Day-Southeast]"
With ActiveSheet.PivotTables("PivotTable1").CubeFields( _
"[Service Category].[Detail COS Desc]")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").CubeFields( _
"[Product].[Product Desc]")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("[Date].[Month].[Month]"). _
VisibleItemsList = Array("[Date].[Month].&[201001]", "[Date].[Month].&[201002]", _
"[Date].[Month].&[201003]", "[Date].[Month].&[201004]")
ActiveWorkbook.ShowPivotTableFieldList = False
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "PaidAmt"
Range("A6").Select
ChDir "C:\Analysis"
ActiveWorkbook.SaveAs Filename:= _
"C:Analysis\CurrentReview.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.Goto Reference:="mcrEduSalesCube"
ActiveWindow.SmallScroll Down:=-12
End Sub