如何识别以检查另一个工作簿是否已打开

时间:2016-03-07 03:34:39

标签: excel vba excel-vba macros

目前我正在使用TASK MANAGER打开工作簿,上次任务未完成,即仍然宏已经在运行另一个工作簿,所以在这里我要检查是否已经打开或运行任何其他工作簿宏;任务管理器关闭当前打开的工作簿,我有如下的简单代码,但我想尝试其他:

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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,无错误处理。