gpt4 book ai didi

vba - Excel VBA 或 VSTO - 如何循环数据透视表上的字段?

转载 作者:行者123 更新时间:2023-12-03 02:16:19 26 4
gpt4 key购买 nike

这里是一些示例 VBA 代码:

Sub Macro1()
Dim pt As PivotTable
Set pt = ActiveSheet.PivotTables("SomePivotTable")
'Set colOfFields = pt.PivotFields
End Sub

第三行不完整/损坏。访问数据透视表中所有字段的集合的正确方法是什么?我需要能够循环它们。实际编码是在 C# VSTO 项目中完成的。

最佳答案

这对我有用(Excel 2003 [11.8146.8202] SP2):

Sub Macro1()
Dim pt As PivotTable
Dim col As PivotFields
Dim c As PivotField

' Name of the pivot table comes from right clicking on the pivot table,
' Table Options..., Name field.
Set pt = ActiveSheet.PivotTables("PivotTable1")
Set col = pt.PivotFields
For Each c In col
Debug.Print c.Name
Next
End Sub

关于vba - Excel VBA 或 VSTO - 如何循环数据透视表上的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/341221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com