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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,223,365
Messages
6,171,653
Members
452,415
Latest member
mansoorali

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