Checking whether Excel is already open

1

10_a_c

Hello:

I have a VB form which will load Excel but I want to add code which will
first check to see whether Excel is already open and then branch accordingly.
I assumed that Excel.Visible = True would take care of that but it is not
working.

Let me thank you in advance for any and all suggestions.
 
D

Dave Patrick

Here's what I do.

If IsExecuting("excel.exe") = True Then
Set oExcel = GetObject(, "Excel.Application")
Else
Set oExcel = CreateObject("Excel.Application")
End If

Public Function IsExecuting(sProc)
Dim list As Object
Set list = GetObject("winmgmts:").ExecQuery( _
"select * from win32_process where name='" & sProc & "'")
If list.Count > 0 Then IsExecuting = True
End Function


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
 
1

10_a_c

Dave:


Thanks for the code.


10_a_c

Dave Patrick said:
Here's what I do.

If IsExecuting("excel.exe") = True Then
Set oExcel = GetObject(, "Excel.Application")
Else
Set oExcel = CreateObject("Excel.Application")
End If

Public Function IsExecuting(sProc)
Dim list As Object
Set list = GetObject("winmgmts:").ExecQuery( _
"select * from win32_process where name='" & sProc & "'")
If list.Count > 0 Then IsExecuting = True
End Function


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

10_a_c said:
Hello:

I have a VB form which will load Excel but I want to add code which will
first check to see whether Excel is already open and then branch
accordingly.
I assumed that Excel.Visible = True would take care of that but it is not
working.

Let me thank you in advance for any and all suggestions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top