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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,929
Messages
6,175,457
Members
452,643
Latest member
gjcase

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