excel - 无法设置 PivotItem 类的 Visible 属性
问题描述
当我从数据透视表的“更改数据源”部分更改数据时,我收到一条错误消息。我每个月都必须这样做。调试发生在“.PivotItems(pi.Name).Visible = True”这一行。有没有办法可以向 VBA 添加代码以获取在更改数据源部分输入的新数据。当我第一次使用这个宏时,它创建了 13 个数据透视表,现在有了新数据,我需要创建 24 个数据透视表,但它只创建 13 个数据透视表,然后进行调试。假设它仍在识别先前的数据。请在下面查看我的编码。
On Error GoTo errHandler
Application.DisplayAlerts = False
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim strPF As String
Dim strPI As String
Set ws = Sheets("Invoice PVTTBL Template")
Set pt = ws.PivotTables(1)
Set pf = pt.PageFields(1)
strPF = pf.Name
For Each pi In pf.PivotItems
strPI = Left(pi.Name, 31)
On Error Resume Next
Sheets(strPI).Delete
On Error GoTo 0
ws.Copy After:=Sheets(Sheets.Count)
With ActiveSheet
.Name = strPI
With .PivotTables(1).PivotFields(strPF)
.PivotItems(pi.Name).Visible = True
.CurrentPage = pi.Name
End With
End With
Next pi
ws.Activate
MsgBox "Invoices Created"
exitHandler:
Application.DisplayAlerts = True
Exit Sub
errHandler:
MsgBox "Could not create sheets"
Resume exitHandler
End Sub
解决方案
推荐阅读
- javascript - io.connect('http://localhost:4000) 是什么意思?
- javascript - 如何从 Vue Material DatePicker 获取绑定日期?
- java - 如何在 Spring Boot 中创建上传文件列表?
- css - React Bootstrap 中的深色下拉菜单项
- javascript - 我如何在javascript中制作金字塔?
- mainframe - //AMSDUMP DD 和 //SYSPRINT DD SYSOUT=A 语句是否相同?
- reactjs - 使用 React.js 的动态导航栏
- javascript - react-router-dom 中的链接删除 css
- assembly - 为什么 .data 段不是 ASLR 随机的?
- python - 如何在 AWS Lambda 函数中重用数据库连接?