0

我需要一键删除 Excel 中的列和图像。我有允许我删除图像的宏,但它不会删除列。

Sub RemoveDrawingObjects()

 'Removes any drawing / chart / shapes / ocx control objects from the active worksheet.

Dim iCount As Integer
Dim Embedded_Objects As Integer

Embedded_Objects = ActiveSheet.Shapes.Count

For iCount = Embedded_Objects To 1 Step -1
    ActiveSheet.Shapes(iCount).Delete
Next iCount

End Sub

这是我用来删除图像的代码,效果很好,我将如何让它删除突出显示的列。

欢迎任何建议或提示。

我的提示是删除图像,然后只删除列,但他们希望一键完成所有操作。

4

1 回答 1

1

如果该列已被选中,则:

Sub RemoveDrawingObjects()

'Removes any drawing / chart / shapes / ocx control objects from the active worksheet.

Dim iCount As Integer
Dim Embedded_Objects As Integer

Embedded_Objects = ActiveSheet.Shapes.Count

For iCount = Embedded_Objects To 1 Step -1
    ActiveSheet.Shapes(iCount).Delete
Next iCount

'delete active column
ActiveCell.EntireColumn.Delete

End Sub

此外,删除所有形状的更简单方法是:

Sub RemoveDrawingObjects()

'Removes any drawing / chart / shapes / ocx control objects from the active worksheet.
Dim shp_fordelete As Shape
For Each shp_fordelete In ActiveSheet.Shapes
    shp_fordelete.Delete
Next shp_fordelete

'delete active column
ActiveCell.EntireColumn.Delete

End Sub
于 2013-08-29T15:35:16.990 回答