我有这段代码用于准备保存和保存文件,但是它会导致 Excel“遇到错误”并关闭。我已将错误归结为 .execute 行。
为什么这会导致崩溃,是否有解决方法?
Sub Save_close()
Dim Ws As Worksheet
Dim Wb As Workbook
Application.DisplayAlerts = False
MsgBox "Do you want to Save a new copy", vbYesNo, "Save New"
If vbYes Then
Workbooks("A380 Master.xlsm").Sheets("OutPutSheet").Range("C:C", "F:F").Delete
For Each Ws In ActiveWorkbook.Sheets
If Not Ws.Name = "OutputSheet" Or Ws.Name = "Sheet1" Then
Ws.Delete
ElseIf Ws.Name = "OutputSheet" Or Ws.Name = "Sheet1" Then
End If
Next Ws
With Application.FileDialog(msoFileDialogSaveAs)
.Show
.Execute
End With
ElseIf vbNo Then
'Workbooks("A380 Master.xlsm").Sheets("OutPutSheet").Range("A1").Select
End If
End Sub