从Excel中删除TableStyle
我已使用以下语句将 TableStyle 添加到 Excel 工作簿:
ActiveWorkbook.TableStyles.Add("PivotTable SS")
我可以使用以下方式删除它:
ActiveWorkbook.TableStyles("PivotTable SS").Delete
在决定是否删除之前,如何以编程方式检查它是否已存在?
目前我正在循环遍历所有表格样式并进行选择性删除:
For Each ts In ActiveWorkbook.TableStyles
If ts.Name = "PivotTable Style 1" Then
ts.Delete
End If
Next ts
但是,这很耗时。如何在不循环的情况下检查数据透视表是否存在并删除它?
谢谢 :)
I have added a TableStyle to excel workbook using the statement:
ActiveWorkbook.TableStyles.Add("PivotTable SS")
I can delete it using:
ActiveWorkbook.TableStyles("PivotTable SS").Delete
How can I programmatically check if it already exists before deciding whether to delete or not?
Currently I am looping through all the table styles and doing a selective delete:
For Each ts In ActiveWorkbook.TableStyles
If ts.Name = "PivotTable Style 1" Then
ts.Delete
End If
Next ts
However, this is time-consuming. How can I just check for the pivot table existence and delete it without looping?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试将样式分配给变量。如果变量为 Nothing,则该样式不存在。如果样式不存在并且您尝试分配变量,您将收到错误消息,因此您需要暂时暂停错误处理。
You can try assigning the style to a variable. If the variable is Nothing, then the style does not exist. If the style does not exist and you try to assign the variable, you will get an error message, so you need to temporarily suspend the error handling.