2016-03-07 41 views
0

目前我使用任務管理器打開工作簿,一段時間以前的任務沒有完成,亦即仍然宏已運行的另一個工作簿的,所以在這裏我婉,以檢查是否有其他工作簿已打開或正在運行的宏;通過任務管理器關閉當前打開的工作簿,我有簡單的代碼按以下,但我想嘗試別的:如何識別檢查,如果其他工作簿已經打開

If thisworkbook.name <> activeworkbook.name then 
call sendemail ' don't need code 
else 
Call Run_Dashboard 
End if 

回答

1
Dim wb as Workbook 
On Error Resume Next      '//this is VBA way of saying "try"' 
Set wb = Application.Workbooks(wbookName) 
If err.Number = 9 then      '//this is VBA way of saying "catch"' 
    'the file is not opened...' 
End If 
0
Function Is_Workbook_Open(byval WB_Name as String) as Boolean 
Dim WB as Workbook 
For each WB in Application.Workbooks 
    if WB.Name = WB_Name then 
     Workbook_Open = True 
     Exit Function 
    End if 
Next WB 
End Function 

回答True如果打開工作簿,沒有錯誤處理。

相關問題