excel - 删除整个工作簿中的元素
问题描述
继续上一个查询:
我想去掉我的形状。
为此,我使用了以下代码:
Sub asbuilremove()
Dim shp As Shape, sh As Worksheet
Set ass = sh.Shapes("AsBuiltBox")
For Each sh In ThisWorkbook.Sheets
For Each shp In sh.Shapes
ass.Delete
Next
Next
End Sub
根据此处的示例:
https://officetricks.com/vba-macro-delete-shapes-excel-workbook-objects-boxes/
但我收到错误: 运行时错误 5 无效的过程调用或参数
那么如何删除我之前创建的 texbox(object) 呢?
解决方案
尝试以下操作:
Dim shp As Shape, sh As Worksheet
For Each sh In ThisWorkbook.Worksheets 'loop through all worksheets
On Error Resume Next 'disable error reporting (next line will throw an error if AsBuiltBox does not exist)
Set shp = sh.Shapes("AsBuiltBox")
On Error GoTo 0 'always re-enable error reporting
'if AsBuiltBox exists delete it
If Not shp Is Nothing Then
shp.Delete
End If
Next sh
它将删除AsBuiltBox
所有工作表上命名的形状(如果存在)。
推荐阅读
- office-js - 我如何阅读outlook2013的附件?
- deep-learning - 在 onnx-runtime 的帮助下推断 LSTM 模型时出错。无效参数错误
- html - 我可以在浏览器中运行 Go 编译器吗?
- angular - 如果关闭,如何在角材料垫抽屉中隐藏组件
- python - 为什么会出现这个nameError
- bigcommerce - 必须从所有用户的视图中隐藏零件编号和 Sku
- reactjs - 加载 PIXI 纹理,处理失败
- python - 在python中切割window.open的一部分(网页抓取)
- python - Pandas:基于另一列的前一行值的条件累积和
- javascript - 如果我的任务日期是当前的,那么它会在我的今天任务中显示任务