Check for 2 instances of Excel

In Excel VBA I wish to determine if 2 sessions/instances of Excel is open, prior to allowing a macro to continue.  I have found with some macros if 2 instances of Excel are open it has some unwanted consequences so I want to check a the beginning of the macro if 2 instances of Excel are open..
upobDaPlayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Are you talking about two workbooks open in the same instance of Excel or actually two instances of Excel itself? I ask because I thought that with the modern versions of Excel that that wasn't possible without a registry edit.
0
Martin LissOlder than dirtCommented:
If it's two workbooks then you can call this little Function and it will return True or False

Function isMoreThanOneOpen() As Boolean

If Workbooks.Count > 1 Then
    isMoreThanOneOpen = True
End If

End Function

Open in new window

0
Dale FyeOwner, Developing Solutions LLCCommented:
You might want to take a look at my article on Automating Excel from Access.  This particular article focuses on the code necessary for identifying multiple instances of Excel, and enumerating each of those.

It was written for Access, and thus uses table to store info rather than arrays or hidden worksheets, but I think you will find what you are looking for in that article.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

upobDaPlayaAuthor Commented:
Its actually for two instances of Excel.  I can go to Windows/Programs, etc and actually open 2 instances of Excel not 2 workbooks.  For a particular macro I have for some reason if 2 instances of Excel is open it creates issues..
0
upobDaPlayaAuthor Commented:
Dale, I am not following the part in the article for "MSDN reference for IIDFromString"...Do I need to save that as a reference.  In addition can I get more clarification on what I need to do for "MSDN reference for AccessibleObjectFromWindow"  Do I need to save this as a reference to my machine...
0
Martin LissOlder than dirtCommented:
This piece of code that I found on the web says that it will tell you if there's more than one. I can't test it.

Sub InstanceCount()
Dim objList As Object, objType As Object, strObj$
strObj = "Excel.exe"
Set objType = GetObject("winmgmts:").ExecQuery("select * from win32_process where name='" & strObj & "'")
If objType.Count > 1 Then
MsgBox objType.Count & " Excel instances are running on your system.", , "More than one instance"
Else
MsgBox "Only this instance is running on your system.", , "One and done"
End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
upobDaPlayaAuthor Commented:
Martin..I will try tomorrow and close the question.  Thanks for your patience.
0
Martin LissOlder than dirtCommented:
I was able to create two instances of Excel and testing showed that the code I found does work.
0
upobDaPlayaAuthor Commented:
It worked !
0
Martin LissOlder than dirtCommented:
I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.