From the course: Excel VBA: Managing Files and Data

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Detect whether a file is open

Detect whether a file is open - Microsoft Excel Tutorial

From the course: Excel VBA: Managing Files and Data

Start my 1-month free trial

Detect whether a file is open

- [Instructor] When you write VBA code that interacts with other Excel workbooks, you need to make sure that those workbooks are in fact open. In this movie, I will demonstrate a technique for determining whether another workbook is in fact open. My sample file is 0203, check if open and you can find it in the chapter two folder of the exercise files collection. I don't need to work with any of the data or the chart in the main workbook so, I'll press ALT-411 to move to the Visual Basic Editor. And here I have a code module that contains a function and also a subroutine that calls the function. I'll describe the subroutine first. What it does, is it determines whether there is an open workbook in other words a member of the workbooks collection that is named target .XLSX. If that file is open, it will be part of the workbooks collection and our function will return true. However, if there is no file with that name…

Contents