Nhiều khi chúng ta muốn xóa toàn bộ shape trên một sheet của excel. Thật vậy, tôi từng gặp tình huống tạo graph trên excel. Nhưng output đi ra cứ có những đường lạ xuất hiện trên sheet, mặc dù file được tạo mới hoàn toàn. Và giải pháp là trước khi tiến hành tạo graph, chúng tôi phải xóa toàn bộ shape nếu có trên sheet.
Tất nhiên nếu chúng ta xóa có điều kiện, thì đây là đoạn code đáng tham khảo:
Nguồn:
Mã:
Sub DeleteAllShapes()
'PURPOSE: Remove All Shape Objects From The Active Worksheet
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
shp.Delete
Next shp
End Sub
Mã:
Sub DeleteAllShapes()
'PURPOSE: Remove All Shape Objects From The Active Worksheet (Excludes Charts/Comments)
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type <> msoChart And shp.Type <> msoComment Then shp.Delete
Next shp
End Sub
Bạn cần đăng nhập để thấy link