Opening workbooks if not already

corquando

Board Regular
Joined
Jan 8, 2009
Messages
82
Greetings, and apologies if I missed a previous discussion of this topic.

Excel2003. VBA.

I have a set of workbooks, any of which may be opened at any time from a master workbook. One of them has to be open only during certain functions, and then must be closed. This can happen 2 or 3 times during a run, and it is not set in stone that the open or closed status happens in a particular order.

So, I have been trying to develop a few lines of code that will check to see if the workbook is open. If not, it would then open it; if so, it would simply move on.

I have used:

If Windows("MyWKBK").Visible = False then
Workbooks.Open("C:\MyWKBK")
End If

and

If Workbooks("MyWKBK").IsInplace = False then
Workbooks.Open("C:\MyWKBK")
End If

and

If Workbooks("C:\MyWKBK").IsInplace = False then
Workbooks.Open("C:\MyWKBK")
End If

and

If Workbooks("C:\MyWKBK").Windows.Visible = False then
Workbooks.Open("C:\MyWKBK")
End If

but none of them work. The usual error is "Subscript out of range" meaning it can't see the object, but that's the point. If it can't see the object, I want it to open the object.

I'm missing something obvious I'm sure, but I cannot say what.

Thank you in advance for your wisdom and patience.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Mr. (Dr.?) Poulsom:

Bravo.

I thank you for your quick advice. It was a bit more elegant than I had anticipated, but it also teaches me a bit about some approaches to other difficulties I've been having.

Again, many thanks. I have bookmarked your page for future reference.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,680
Members
449,091
Latest member
peppernaut

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