Results 1 to 3 of 3
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Use vba to detect if excel is open.


    Hello, I am wondering if there is a way to determine of a user has an open version of excel running. I have people who are opening a .xls file from the internet. These files are being OPENED NOT SAVED to their local machines. So I wonder if I can just figure out if excel is running, then interact with it from there...

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Check out this site:
    http://www.accessmvp.com/kdsnell/EXC...m#WriteRstFile

    Look for this comment in the code
    ' Establish an EXCEL application object

    The code below it checks if Excel is open...

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Here is a routine I found a few years back that may help. I've included a test routine (and I started excel and tested it just now) and it resulted in True. I'm using Ac2010, but have used this with 2003.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : IsExeRunning
    ' Author    :  James Barash(AccessD)
    ' Created   : 3/17/2009
    ' Purpose   : To determine if a specific program is currently running.
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs:  The name of the program
    ' Dependency: N/A
    '------------------------------------------------------------------------------
    '
    Public Function IsExeRunning(strExeName As String) As Boolean
    Dim objProcesses As Object, objProcess As Object
      IsExeRunning = False
      Set objProcesses = GetObject("winmgmts://" & Environ$("ComputerName") _
     & "/root/cimv2").ExecQuery("select * from Win32_Process")
      If Not objProcesses Is Nothing Then
        For Each objProcess In objProcesses
          If objProcess.name = strExeName Then
              IsExeRunning = True
              Exit For
          End If
        Next
        Set objProcess = Nothing
        Set objProcesses = Nothing
      End If
    End Function
    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : jtestit
    ' Author    : Jack
    ' Created   : 3/17/2009
    ' Purpose   : Test routine to ensure IsEXERunning function is working
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs: N/A
    ' Dependency: N/A
    '------------------------------------------------------------------------------
    '
    Sub jtestit()
    Dim smyEXE As String
    
    'smyEXE = "msaccess.exe"
    smyEXE = "excel.exe"
    Debug.Print "Is " & smyEXE & " running: " & IsExeRunning(smyEXE)
    End Sub
    Debug.print output
    Is excel.exe running: True

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Need to detect right arrow key
    By ChuckColeman1812 in forum Programming
    Replies: 4
    Last Post: 09-12-2012, 08:08 AM
  2. Excel code not working with Excel open
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 07-11-2011, 12:12 PM
  3. Detect When Two Related Fields are Dirty
    By caddcop in forum Forms
    Replies: 2
    Last Post: 06-09-2011, 05:44 AM
  4. How do I detect new records.
    By jcollins in forum Programming
    Replies: 3
    Last Post: 03-17-2011, 03:48 PM
  5. VBA to open excel, import on close of excel
    By bdaniel in forum Programming
    Replies: 0
    Last Post: 03-20-2010, 02:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums