Re: Checking whether Excel is already open

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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" wrote:
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.

.



Relevant Pages

  • Re: Late Binding
    ... GetObject has two optional arguments. ... The comma is just a quick way of ... You could just as easily write: Set oExcel = ... > On Error GoTo 0 ...
    (microsoft.public.excel.programming)
  • Re: Detect If Excel is running using VBA
    ... Just use GetObject with the Excel progid: ... dim oExcel as object ... set oExcel = getobject ...
    (microsoft.public.access.modulesdaovba)
  • Re: Late Binding
    ... Check the 'GetObject Function' in XL VBA help. ... Microsoft Most Valuable Professional (MVP) 2000-2004 ... on the 2nd line of code where it says: Set oExcel = ... > On Error GoTo 0 ...
    (microsoft.public.excel.programming)
  • Re: Late Binding
    ... This is because GetObject has two parameters, pathname and class. ... on the 2nd line of code where it says: Set oExcel = ... > On Error GoTo 0 ...
    (microsoft.public.excel.programming)