[英]How to check if another workbook is open?
我通过使用任务管理器来打开工作簿。 有时上一个任务没有完成,即该宏已经在另一个工作簿中运行。
我想检查是否有其他工作簿已经打开或正在运行宏; 由任务管理器关闭当前打开的工作簿。
我有如下简单的代码:
If thisworkbook.name <> activeworkbook.name then
call sendemail ' don't need code
else
Call Run_Dashboard
End if
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
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,没有错误处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.