Results 1 to 4 of 4

Thread: how to check if excel is open

  1. #1
    donjt81 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jan 2006
    Posts
    9
    Reputation
    0

    how to check if excel is open

    Hi I am opening MS Excel from my vb.net code. But at certain places I want to see if the Excel application is already open. If it is open then i dont need to open Excel again but if it is not open then i need to open excel.

    Is there some way to check and see if excel is running in the task manager maybe, i dont know.

    Can someone help?

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,457
    Reputation
    2727
    If you are doing automation check if your instance of the Excel Application object is Nothing.
    If you just have Excel started as a normal process and want to see if it's still there, use Process.GetProcessesByName("excel")

  3. #3
    JuggaloBrotha's Avatar
    JuggaloBrotha is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Lansing, MI; USA
    Posts
    4,360
    Reputation
    971
    Code:
    Private Function CheckExcel() As Boolean
      If Ubound(Diagnostics.Process.GetProcessesByName("Excel")) > 0 Then
        Return True
      Else
        Return False
      End If
    End Function

    and to use this:
    Code:
    If CheckExcel() = True Then
       'Code here for if Excel is open already
    Else
       'Code here to open Excel and whatnot
    End If
    Currently using: VS 2010 Ultimate on Win7 Ultimate x64.


  4. #4
    donjt81 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jan 2006
    Posts
    9
    Reputation
    0
    Thanks guys I used the object is nothing... method worked fine for me

    Thanks again

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking