Когда я добавляю 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
Я просто не хочу, чтобы всплыло предупреждение "Вы действительно хотите удалить лист".