Public Function ExistPivot(PTName As String) As Boolean
Dim WS As Worksheet, PT As PivotTable
ExistPivot = False
For Each WS In ActiveWorkbook.Worksheets
For Each PT In WS.PivotTables
If PT.Name = PTName Then
ExistPivot = True
Exit Function
End If
Next PT
Next WS
End Function
1 回答
是否可以选择创建VBA用户定义函数?在这种情况下,我建议
并在工作表中将其用作
=ExistPivot("xxx")
,结果将为TRUE或FALSE