0

I open a workbook by using TASK MANAGER. Sometimes the previous task is not completed i.e. the macro is already running in another workbook.

I want to check if any other workbook is already open or running macro; close current opened workbook by task manager.

I have simple code as per below:

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

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

Comments

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 

Answers True if the Workbook is opened, no error handling.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.