gravanoc
Active Member
- Joined
- Oct 20, 2015
- Messages
- 351
- Office Version
- 365
- Platform
- Windows
- Mobile
I have a straightforward project that takes an .xml as input, turns into .xlsx, filters by some specified criteria, then summarizes that filtered data into a pivot table. The last part seems to be a problem for a person with Excel 2013. I pulled up the Compatibility Checker on a finished transformation and the closest items dealing with the pivot table & its essentials were problems for 2010 and older.
Compatibility Checker:
The error is "Invalid procedure or argument," and points to the line with PivotCaches.Create. Since it works fine for everyone else I'm having trouble determining whether there is a solution involving a pivot table in this guy's case, or if I should make a separate version without.
Code:
Compatibility Checker:
The error is "Invalid procedure or argument," and points to the line with PivotCaches.Create. Since it works fine for everyone else I'm having trouble determining whether there is a solution involving a pivot table in this guy's case, or if I should make a separate version without.
Code:
VBA Code:
Sub PivotInitialize(wbLab As Workbook, wksFiltered As Worksheet, _
tblFilter As ListObject, rngDestination As Range)
Dim wksSummary As Worksheet
Dim rngPivot As Range
Dim wbConnect As WorkbookConnection
Dim pvtCache As PivotCache
Dim pvtTable As PivotTable
Set wksSummary = Sheets.Add(After:=Sheets(wksFiltered.Name))
Set rngPivot = wksSummary.Range("B2")
wksSummary.Name = "Pivot"
Set wbConnect = wbLab.Connections.Add2( _
Name:="WorksheetConnection_" & wbLab.Name & "!" & tblFilter.Name, _
Description:="", ConnectionString:="WORKSHEET;" & wbLab.Path _
& Application.PathSeparator & wbLab.Name, CommandText:=wbLab.Name & "!" & tblFilter.Name, _
lCmdtype:=7, CreateModelConnection:=True, ImportRelationships:=False)
' -----------------------------------------------------------
' ----------------- ERROR ---------------------------------
Set pvtCache = wbLab.PivotCaches.Create(SourceType:=xlExternal, SourceData:= _
wbConnect, Version:=7)
' -----------------ERROR----------------------------------
' ------------------------------------------------------------
Set pvtTable = pvtCache.CreatePivotTable(TableDestination:=rngPivot, TableName:= _
"pvtLink", DefaultVersion:=7)
wksSummary.Activate
With pvtTable
.ColumnGrand = True
.HasAutoFormat = True
.DisplayErrorString = False
.DisplayNullString = True
.EnableDrilldown = True
.ErrorString = ""
.MergeLabels = False
.NullString = ""
.PageFieldOrder = 2
.PageFieldWrapCount = 0
.PreserveFormatting = True
.RowGrand = True
.PrintTitles = False
.RepeatItemsOnEachPrintedPage = True
.TotalsAnnotation = True
.CompactRowIndent = 1
.VisualTotals = False
.InGridDropZones = False
.DisplayFieldCaptions = True
.DisplayMemberPropertyTooltips = True
.DisplayContextTooltips = True
.ShowDrillIndicators = True
.PrintDrillIndicators = False
.DisplayEmptyRow = False
.DisplayEmptyColumn = False
.AllowMultipleFilters = False
.SortUsingCustomLists = True
.DisplayImmediateItems = True
.ViewCalculatedMembers = True
.FieldListSortAscending = False
.ShowValuesRow = True
.CalculatedMembersInFilters = True
.RowAxisLayout xlTabularRow
.PivotCache.RefreshOnFileOpen = False
.RepeatAllLabels xlRepeatLabels
End With
Call PivotTableSetup(wbLab, wksSummary, pvtCache, pvtTable)
End Sub