Question

We have a little piece of VBA code that worked perfectly for ages. It was essentially:

Me.PivotTables("APivot").PivotFields("AField").CurrentPage = "Some text"

This worked until Excel 2013, where the line would fail with an unspecific error:

Runtime error 5:
Invalid procedure call or argument.

By trial and error we figured that in Excel 2013 you cannot navigate to a pivot table page with code until the user has navigated to that page manually using the Excel interface. As soon as the user navigates to a page, navigating to that page with code will always succeed (until you close the workbook). So in order for the code to be able to navigate to any page, we first need the user to go through all of them manually.

A workaround to that would be changing the value of the underlying cell instead:

Me.PivotTables("APivot").PivotFields("AField").CurrentPage.LabelRange.Value = "Some text"

We are currently forced to use this workaround, but it feels hackish.

Exactly what in Excel 2013 causes this behaviour? Is there some bit one now needs to do first in order to navigate to a page (poke something, load some data in some way etc)?

EDIT: Same problem occurs in Office 2016.

Was it helpful?

Solution

I'm not sure how they become "hidden" in the first place, but I just ran into the same problem and found this post.

The solution from there is to right-click the filter field (on the spreadsheet cell, not the field list) and under field settings, make sure the items are not hidden.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top