Excel 2013 Pivot table won't change current page until navigated to manually

孤街浪徒 提交于 2019-12-12 16:02:34

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14939292/excel-2013-pivot-table-wont-change-current-page-until-navigated-to-manually

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!