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
From the course: Excel VBA: Managing Files and Data
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Determine if a workbook exists4m 41s
-
(Locked)
Determine if a folder (directory) exists4m 22s
-
(Locked)
Detect whether a file is open4m 40s
-
(Locked)
Open a workbook3m 23s
-
(Locked)
Close a workbook5m 34s
-
(Locked)
Save a workbook under a new name4m 15s
-
(Locked)
Save a workbook as a CSV file5m 19s
-
-
-
-
-
-
-
-