Find a Workbook

User avatar
SammyB
StarLounger
Posts: 93
Joined: 04 Mar 2010, 16:32

Find a Workbook

Post by SammyB »

Is there a good way to look to see if the current instance of Excel has workbook A open; and if not, see if there is another instance of Excel that has workbook A open; and finally if not, open workbook A with a new instance of Excel? I'd like this to work with any version of Excel. It would be even nicer if it would still work when two different versions of Excel were installed and the macro was running with Excel 2003 and workbook A was open in Excel 2007. TIA --Sam

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Find a Workbook

Post by HansV »

You can loop through the Application.Workbooks collection to see if workbook A is open in the current instance.
If not, you should be able to use GetObject to see if workbook A is open in another instance.
If not, you can use CreateObject to start a new instance of Excel and open the workbook.

(But in my opinion, this is undesirable.)
Best wishes,
Hans

User avatar
SammyB
StarLounger
Posts: 93
Joined: 04 Mar 2010, 16:32

Re: Find a Workbook

Post by SammyB »

That's what I was trying to do, but the GetObject is not working for me. I'll try it again.

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Find a Workbook

Post by HansV »

Could you tell us what you want to accomplish? End users shouldn't be running multiple instances of Excel, particularly not different versions, and developers should be smart enough to know what they're doing.
Best wishes,
Hans

User avatar
SammyB
StarLounger
Posts: 93
Joined: 04 Mar 2010, 16:32

Re: Find a Workbook

Post by SammyB »

Ouch! You answered my main question in your first post: I just wanted to make sure that I was approaching it correctly.

> want to accomplish
I've got nothing much to do, so I was just trying to find a foolproof way of finding if a Workbook was running. If I continue to have nothing to do, I'll rewrite the code and post back a more specific question. It will be Friday: I have real work for tomorrow. But now, I off to bike ride.

> End users shouldn't ...
My users run everything from XL 97 on up, and they usually expect my stuff to work on their maching, but there's never enough time to test on every machine. Some of the users have two copies of Excel: I usually don't worry if it works for them, but sometimes I have to fix it so that it does. That's why I get paid the big bucks, LOL.
Last edited by SammyB on 31 Mar 2010, 20:47, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Find a Workbook

Post by HansV »

Does the code in The Code Net do what you want?
Best wishes,
Hans

User avatar
SammyB
StarLounger
Posts: 93
Joined: 04 Mar 2010, 16:32

Re: Find a Workbook

Post by SammyB »

That's very interesting! I'll have to check what happens with Excel 2007. I actually think that their example can be done with a simple GetObject. I think that my problem is xlsx and xlsm vs. xls. I'm going to have to loop GetObject thru the various Excel extensions.

Thanks again! --Sam