From the course: Excel VBA: Managing Files and Data

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Detect whether a file is open

Detect whether a file is open

- [Instructor] When you write VBA code that affects other Excel workbooks, you need to make sure that those workbooks are open. And in this movie, I will show you a technique for determining whether another workbook is in fact open. The sample file we will create our code in is 02_03_CheckIfOpen. And that is a macro-enabled workbook you can find in the chapter two folder of the exercise files collection. We won't work with the data or the chart on the worksheet here. So I'll press Alt + F11 to move to the Visual Basic editor. Here I have a function named CheckIfOpen, and it is given the name of the file as a string and returns either true or false. And that is called a Boolean value. I'll describe the code here in a second. The function is called by the CheckIfWkbkOpen subroutine. I have entered the name of the file that we're going to check. You can enter a different name or get the name of the file from your user. And then after determining whether it is open or not, true or false…

Contents