Checking for an active workbook

mcgrathm

New Member
Joined
Mar 18, 2002
Messages
3
I want to be able to check whether a workbook is already in memory so that my macro can either switch to it or load it up from the network.
This message was edited by mcgrathm on 2002-03-19 08:24
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try the following code:

BookName = "Insert Workbook name to check"
BookCount = Workbooks.Count
For i = 1 To BookCount
If BookName = Workbooks(i).Name Then
BookCheck = 1
GoTo 1
Else: BookCheck = 2
End If
Next i
1 If BookCheck = 1 Then MsgBox "Workbook is loaded"
If BookCheck = 2 Then Application.GetOpenFilename

Insert the Workbook name to check and then the code checks to see if the workbook is open, if it is not open then it opens the file open dialog box.
 
Upvote 0
Another suggestion:

Function BookOpen(wbName as String) as Boolean
Dim wb as Workbook
On Error Resume Next
Set wb = Workbooks(wbName)
BookOpen = Not (Err.Number > 0)
Exit Function

You can use it like this:

BookOpen("MyBook.xls")

it should run much faster.
 
Upvote 0

Forum statistics

Threads
1,213,560
Messages
6,114,304
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top