ProcessID for Excel Application object

J

Joe Cletcher

I need to find the process ID for an Excel application object specified by my
code.--using Interopt Services. No other Excel processes should be running.

Following code demonstrates problem.

DIM aProcess as New Process
DIM MyExcelProcessID As Integer = -1
DIM XlsProcesses() as Process = Process.GetProcessesByName("Excel")

For Each aProcess in XlsProcesses
aProcess.Kill()
Next
DIM xcApp as New Excel.Application
XlsProcesses = Process.GetProcessesByName("Excel")
MyExcelProcessID = XlsProcesses(0).ID

However, if someother program or user opens an Excel process between the
"Dim XlsProcesses..." and the "XlsProcesses = " statements complete then
XlsProcesses(0).ID is not guaranteed to be the correct Process ID for xcApp.

How do I determine the correct Process ID for xcApp?
 

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