[英]how to check if workbook is closing in deactivate event
解決了
當代碼在workbook_deactivate過程中時,有什么方法可以檢查工作簿是否關閉? 因此,我可以根據用戶是要離開另一個工作簿還是要關閉文件來向用戶通知其他消息。 喜歡以下
Private Sub Workbook_Deactivate()
if thisworkbook.closing then
msgbox "message1"
else
msgbox "message2"
end if
End Sub
我在網上搜索,但根本沒有解決方案。 所以任何幫助將不勝感激
解
我想到了一個把戲。 我在before_close事件中將值1放入Z1000(如果可用)中並停用,我正在檢查Z1000的值。 而已。
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("Z1000").Value = 1 'wherever is avaliable
Me.Saved = True
End Sub
Private Sub Workbook_Deactivate()
If Range("Z1000").Value = 1 Then
MsgBox "quitting"
Else
MsgBox "deactivating"
End If
End Sub
您可以使用BeforeClose
事件檢測到
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' set Cancel to true to prevent it from closing
End Sub
您可以檢查此代碼
ThisWorkbook.Close True
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.