Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Office Automation > Check if Workbook is Open

Thread Tools Display Modes
Old 07-26-2010, 12:54 PM
SubTestEng SubTestEng is offline
Join Date: Mar 2010
Posts: 19
Default Check if Workbook is Open

Good afternoon, everyone!

Does anyone have a suggestion for how I might check to see if a specific Excel Workbook (call it Test.xlsx) is open?

I have a routine that calls a subroutine. Sometimes at the time of the call Test.xlsx is open, sometimes not. So when the subroutine runs, I need it to check first to see if Test.xlsx is open. If it isn't then the subroutine should open it and perform the subroutine's purpose operations. If it is open, it should not try to "re-open" it or worse open a copy of it; it should simply perform the subroutine's purpose operations.

Any ideas? Thanks in advance for your help!
Reply With Quote
Old 07-27-2010, 04:35 PM
Colin Legg's Avatar
Colin Legg Colin Legg is offline
Out Of Office

Retired Moderator
* Expert *
Join Date: Mar 2005
Location: London, UK
Posts: 3,400


I assume this is VB.Net?

There are various levels of complexity to this sort of question - is the workbook open in a single Excel instance, is it open in any of multiple Excel instances, is it open on another user's PC, etc?

It sounds like this is the simplist scenario where you need to check whether the workbook is open in an Excel instance you already have a reference to. You can build a simple function to loop through the Workbooks collection, checking each member in turn for a match.

Hope that helps...
RAD Excel Blog
Reply With Quote
Old 08-11-2010, 08:52 AM
SubTestEng SubTestEng is offline
Join Date: Mar 2010
Posts: 19


Sorry it took so long to get back to you. I have been away from the office. I am running VB.Net using Visual Studio 2010.

To answer your question: It would only be open on my computer as it's not connected to a network. There may or may not be other instances of Excel open.

I think I understand what you mean by looping through the Workbooks collection, but that would beg the question of how do I establish the reference to the particular instance of Excel.

Thanks for any help!

Reply With Quote
Old 08-13-2010, 07:00 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848

I don't know of a source for .NET, but the following should get you started:


-- Mike
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote

excel is open, workbook is open

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..