[英]Delete a specific worksheet from .xlsm file
Trying to delete a worksheet using the following code. 尝试使用以下代码删除工作表。 Throwing an "Object required" error on the delete line.
在删除行上引发“需要对象”错误。 I have tried many variations on this line, ie, s.delete, sheets.s.delete, worksheets.delete, etc.
我已经尝试过这条线上的许多变体,例如s.delete,sheets.s.delete,worksheets.delete等。
Dim s As Worksheet
'Look for existing sheets named "For Export
'If found, delete existing sheet
For Each s In ActiveWorkbook.Sheets
If s.Name = "For Export" Then
Application.DisplayAlerts = False
Workbook.Worksheets.Item(s.Name).Delete
End If
Next s
Try this code : 试试这个代码:
Sub deleteWorksheet()
Dim s As Worksheet, t As String
Dim i As Long, K As Long
K = Sheets.Count
For i = K To 1 Step -1
t = Sheets(i).Name
If t = "For Export" Then
Application.DisplayAlerts = False
Sheets(i).Delete
Application.DisplayAlerts = True
End If
Next i
End Sub
How about: 怎么样:
Sub poiuyt()
Dim s As Worksheet
For Each s In ActiveWorkbook.Sheets
If s.Name = "For Export" Then
Application.DisplayAlerts = False
s.Delete
Application.DisplayAlerts = True
End If
Next s
End Sub
For Each s In ActiveWorkbook.Sheets
If s.Name = ws_name Then
Application.DisplayAlerts = False
Sheets(ws_name).Delete
Application.DisplayAlerts = True
Exit For
End If
Next s
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.