【发布时间】:2019-10-25 19:07:54
【问题描述】:
当我在 sheet("Sheet2").Delete 的任一侧添加 Application.DisplayAlerts = false 和 Application.DisplayAlerts = True 时,我收到 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
我只是不希望弹出“您确定要删除工作表吗”警报。
【问题讨论】:
-
首先关闭私人 Sub 中的 p 是在它自己的线路上。除此之外,错误在哪一行?没有 DisplayAlerts 是否可以工作? Owh 并确保 Sheet2 和 Sheet1 确实存在于您正在使用的工作簿中。
-
粘贴代码后 p 是我。有问题的代码: Application.DisplayAlerts = False Sheets("Sheet2").Delete Sheets("Sheet1").Delete Application.DisplayAlerts = True 没有 application.displayalerts
-
我尝试了这些行,但它没有给我一个错误。你确定有一张名为“Sheet1”和“Sheet2”的工作表吗?
-
如果您点击调试,错误会突出显示哪一行?
-
我确定工作表名称,因为代码有效,但是当我添加 application.displayalert 它正在删除宏按钮所在的页面时停止工作,这可能是问题吗?我刚刚删除了 sheet("sheet1").delete 并且没有问题,但我需要它来删除 sheet 1 而不会弹出