如果工作表不包含数据/图表/图像/绘图/超链接对象或任何其他嵌入对象,我希望将其删除。
我用下面的代码找出了单元格中没有数据时检测和删除空白表的解决方案:
if ( $Worksheet_Function->CountA( $sheet->{Cells} )删除0){$sheet-> ==;}
但如果有图表或非文本对象,它也会删除工作表。
有没有办法识别和删除图纸,如果它完全是空的?
发布于 2011-06-04 11:51:12
如果只有格式设置,将删除工作表,但这应该会按照您的要求执行
Sub chksheet()
Dim wks As Worksheet
Application.DisplayAlerts = False
For Each wks In ActiveWorkbook.Worksheets
If WorksheetFunction.CountA(Cells) = 0 And wks.DrawingObjects.Count = 0 Then
wks.Delete
Else
MsgBox ("has stuff") 'or do nothing here and skip this sheet
End If
Next wks
Set wks = Nothing
Application.DisplayAlerts = True
End Sub
发布于 2011-06-05 21:07:43
您可以更彻底地检查所有想要测试的相关对象
Option Explicit
Sub test()
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
With WS
'default usedrange = 1 so check cell A1 is also empty
If .UsedRange.Count = 1 And IsEmpty(.Cells(1, 1).Value) _
And .UsedRange.Column = 1 _
And .UsedRange.Row = 1 _
And .Comments.Count = 0 _
And .Shapes.Count = 0 _
And .Hyperlinks.Count = 0 _
And .ListObjects.Count = 0 _
And .OLEObjects.Count = 0 _
And .Names.Count = 0 _
And .QueryTables.Count = 0 _
And .SmartTags.Count = 0 Then
MsgBox ("BLANK")
'WS.delete
Else
MsgBox ("NOT BLANK")
End If
End With
Next WS
End Sub
https://stackoverflow.com/questions/3565626
复制相似问题