Excel 2013 failing on PivotCache.Create [VBA]

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
351
Office Version
  1. 365
Platform
  1. Windows
  2. 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:
1650299347003.png
1650299411886.png


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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top