我在表單上有一個命令按鈕代碼,該代碼在保存工作表之前檢查表中的所有單元格是否已完成。如果它們不全部完成,彈出一個用戶窗體消息框並提示,然後返回到表單而不保存。我希望能夠從'BeforeClose'事件中調用它,但是,即使它仍然按照它應該做的操作,在用戶窗體消息框顯示並被卸載之後,它仍然會彈出「保存」對話框。在關閉事件之前禁止保存對話
我竭力壓制保存對話框或自動選擇「取消」,返回到片編輯
Option Explicit
Dim WSh As Worksheet
Dim Create As Boolean
Dim Pipe As Worksheet
Dim LR As Long, i As Long
Dim c As Variant
Dim d As Variant
Dim u As Variant
Dim target As Variant
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Set Pipe = Sheets("Pipe Cleaning")
Select Case Pipe.Range("N1")
Case Is = False
For Each d In Range("L18:L113")
If d.Value >= 1 And d.Value <= 4 Then
Mbox.Show
Exit Sub
End If
Next d
Case Is = True
For Each u In Range("L18:L113")
If u.Value >= 1 And u.Value <= 3 Then
Mbox.Show
Exit Sub
End If
Next u
End Select
Pipe.Activate
Pipe.Unprotect
Range("A8:A15").EntireRow.Hidden = False
For Each c In Range("A8:A15")
Select Case c.Value
Case Is = ""
c.EntireRow.Hidden = True
End Select
Next c
Pipe.Protect
ActiveWorkbook.Save
Application.ScreenUpdating = True
End Sub
另請參見:http://www.mrexcel。 com/forum/excel-questions/748420-suppress-save-dialog-before-close-event.html – pnuts
谷歌似乎顯示了很多答案,我認爲在SE上還有其他人。如果那些不合適,你會介意以什麼方式解釋? – pnuts
他們似乎不適合,因爲他們似乎想要保存工作簿,因爲我不這樣做,只想返回到工作表並重新編輯。顯示警報提到了很多,但這不適用於我 – elmonko