VBA Check for Open Workbook in Excel. We have flexibility to open multiple workbooks at a time in MS office. While running macro we may want to check particular workbook is open or not. Let us see specified Workbook is open or not in the following tutorial.
VBA Check for Open Workbook in Excel
Let us see the following macro to verify weather the Workbook is open or not using Dir Function in Excel VBA.
'VBA Verify for Open Workbook in Excel Sub Check_Open_Workbook() 'Variable declaration Dim oWorkbook As Workbook For Each oWorkbook In Workbooks If oWorkbook.Name = "Test_Workbook.xls" Then MsgBox "Specified Workbook is open.", vbInformation, "VBAF1 : Automation Made Easy" Else MsgBox "Specified Workbook is not open.", vbCritical, "VBAF1 : Automation Made Easy" End If Next End Sub
Note: lets assume ‘Test_Workbook.xls’ Workbook is not available. It shows the following output on the screen.
Output: Here is the output screenshot of above macro.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays in Excel Blog
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers