469,927 Members | 2,022 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Detecting existing Excel instance the .Net way?

In VB6, I would check to see if Excel was already running by this technique

Private m_booExcelCreatedHere As Boolean

Dim xlApp as Excel.Application

On Error Resume Next ' temporarily suppress error handler
Set xlApp = GetObject(,"Excel.Application")
On Error GoTo PROC_ERR ' resume normal error handling
If xlApp Is Nothing Then
Set xlApp = New Excel.Application
' xlApp.Visible = True ' uncomment when debugging to see what's
happening
m_booExcelCreatedHere = True
Else
m_booExcelCreatedHere = False
End If

Later on, I'd use m_booExcelCreatedHere to determine if I should leave Excel
running (perhaps because the user had started it themselves and is working
with other workbooks unrelated to mine) or use xlApp.Quit and set xlApp to
Nothing.

What's the VB.Net way of doing this?
Nov 20 '05 #1
1 7892
Hi,

If Process.GetProcessesByName("excel").GetLength(0) > 0 Then

MessageBox.Show("Excel is running")

Else

MessageBox.Show("Not running")

End If

Ken

----------------------------

"Fred Morrison" <fm*******@erols.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
In VB6, I would check to see if Excel was already running by this technique
Private m_booExcelCreatedHere As Boolean

Dim xlApp as Excel.Application

On Error Resume Next ' temporarily suppress error handler
Set xlApp = GetObject(,"Excel.Application")
On Error GoTo PROC_ERR ' resume normal error handling
If xlApp Is Nothing Then
Set xlApp = New Excel.Application
' xlApp.Visible = True ' uncomment when debugging to see what's
happening
m_booExcelCreatedHere = True
Else
m_booExcelCreatedHere = False
End If

Later on, I'd use m_booExcelCreatedHere to determine if I should leave Excel running (perhaps because the user had started it themselves and is working
with other workbooks unrelated to mine) or use xlApp.Quit and set xlApp to
Nothing.

What's the VB.Net way of doing this?

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Anne Sachleben via AccessMonster.com | last post: by
4 posts views Thread by Josh Behl | last post: by
3 posts views Thread by Ian Dunn | last post: by
9 posts views Thread by Doug Glancy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.