下面的代码删除当前打开的工作簿中的所有空工作表
试试这个
Sub delete()
Application.DisplayAlerts = False
Dim sh As Worksheet
For Each sh In Sheets
If IsEmpty(sh.UsedRange) Then sh.delete
Next
Application.DisplayAlerts = True
End Sub
如果要使用名称指定完整路径,请使用
Sub delete()
Dim wb As Workbook, s As String
s = InputBox("Full workbook path & name")
Dim fileExists As Boolean
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fileExists = fso.fileExists(s)
If fileExist Then
Set wb = Workbooks.Open(s)
For Each Sheet In sh
If IsEmpty(sh.UsedRange) Then
sh.delete
End If
Next
Else
MsgBox "File doesn't exist", vbCritical, "Error"
End If
End Sub