【问题标题】:Error 440 After I add application.displayalerts = false添加 application.displayalerts = false 后出现错误 440
【发布时间】: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 而不会弹出

标签: excel vba


【解决方案1】:

在 cmets 中解决了问题所在,问题是您无法在要删除的工作表上拥有 ActiveX 按钮。您可以使用以下命令来抑制错误和警报:

    On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("Sheet2").Delete
    Sheets("Sheet1").Delete
    Application.DisplayAlerts = True
    On Error GoTo 0

【讨论】:

  • 你绝对的英雄。谢谢
  • 会做,但是当我有你的时候,我可以问一下工作表是否受到保护,在删除工作表之前需要什么代码来取消保护工作表以便可以删除它们我在哪里标记回答为接受 - 发现它是大箭头
  • 我不确定,我认为.Unprotect 是一回事。但我自己从来没有用过。
猜你喜欢
  • 1970-01-01
  • 2016-07-29
  • 1970-01-01
  • 2014-05-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多