当我添加Application.DisplayAlerts = false和Application.DisplayAlerts = True时,工作表的任一面都被删除(“ Sheet2”)。删除时,我将收到440错误。
不知道问题出在哪里,但是没有application.displayalerts,它不会出现问题。
我已经使用谷歌搜索了很久了,我尝试了一些在此处发布的其他问题中提到的几件事。我觉得也许我需要另一行代码或其他内容。
无效的代码:
Private Sub CommandButton1_Click()
Dim numberCopies As Long
Dim currentRow As Long
Dim j As Long
Dim sht As Worksheet
Set sht = Sheets("sheet3")
currentRow = 2
Do While Not IsEmpty(sht.Cells(currentRow, 1))
numberCopies = sht.Cells(currentRow, 1)
For j = 2 To numberCopies
sht.Rows(currentRow).Copy
sht.Rows(currentRow).Insert Shift:=xlDown
currentRow = currentRow + 1
Next j
currentRow = currentRow + 1
Loop
Application.CutCopyMode = False
sht.Columns(1).Delete
Dim Path As String
Dim Filename1 As String
Dim Filename2 As String
Path = ThisWorkbook.Path & "\"
Filename1 = Range("B1")
Filename2 = Range("D1")
Application.DisplayAlerts = False
Sheets("Sheet2").Delete
Sheets("Sheet1").Delete
Application.DisplayAlerts = True
ActiveWorkbook.SaveAs Filename:=Path & Filename1 & "-" & Filename2 & ".csv", FileFormat:=xlCSV
MsgBox "This usage file as been saved in the same folder as the Usage Upload Creator, it is saved as " & ActiveWorkbook.Name & " This workbook will now close and you can upload your usage file on CPQ. Thank You."
ActiveWorkbook.Close False
End Sub
我只是不想弹出“您确定要删除工作表”警报。
答案 0 :(得分:0)
在注释中找出问题所在,问题是您无法在要删除的工作表上放置ActiveX按钮。您可以使用以下方法抑制错误和警报:
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Sheet2").Delete
Sheets("Sheet1").Delete
Application.DisplayAlerts = True
On Error GoTo 0