not one that is saved in a directory that is open, but one that is open as new, Book1, Book2, etc.
not one that is saved in a directory that is open, but one that is open as new, Book1, Book2, etc.
If you just need to know if the Excel app is open in order to establish an object variable in VBA, consider:
Also review https://stackoverflow.com/questions/...s-already-openCode:' Establish an EXCEL application object On Error Resume Next Set xlx = GetObject(, "Excel.Application") If Err.Number <> 0 Then Set xlx = CreateObject("Excel.Application") blnEXCEL = True End If Err.Clear On Error GoTo 0
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
I didn’t follow how that would know if an excel file is open. The answer in stack overflow seems to have answer it in a case when the file is saved in a directory.
The first example is found code. I just know it works in my procedure. If Excel is already open, determines which method to use for setting the object variable.
If a workbook has not been saved to folder, then it cannot be an 'opened' file, it's just a new document in progress.
Exactly what do you need to accomplish?
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Here's a function to see if some "program" is running. There is also a test routine to try it(below).
Test routine to see if EXcel is running on my machineCode:' 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 10 IsExeRunning = False 20 Set objProcesses = GetObject("winmgmts://" & Environ$("ComputerName") _ & "/root/cimv2").ExecQuery("select * from Win32_Process") 30 If Not objProcesses Is Nothing Then 40 For Each objProcess In objProcesses 50 If objProcess.name = strExeName Then 60 IsExeRunning = True 70 Exit For 80 End If 90 Next 100 Set objProcess = Nothing 110 Set objProcesses = Nothing 120 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 10 smyEXE = "excel.exe" ' "msaccess.exe" 20 Debug.Print "Is " & smyEXE & " running: " & IsExeRunning(smyEXE) End Sub
Thanks for the code and example. But I think is not right in catching it, I have Excel open and isExerunning is False. Didn't go into the loop.
????
I just set this up on my PC
First run I did not have excel running, I started excel and ran routine againCode:Sub jtestit() Dim j As Integer Dim smyEXE(5) As String 10 smyEXE(0) = "msaccess.exe" 20 smyEXE(1) = "firefox.exe" 30 smyEXE(2) = "i_view32.exe" 40 smyEXE(3) = "excel.exe" 50 smyEXE(4) = "explore.exe" 60 smyEXE(5) = "greenshot.exe" 70 For j = 0 To 5 80 Debug.Print "Is " & smyEXE(j) & " running: " & IsExeRunning(smyEXE(j)) 90 Next j End Sub
With these results
I tried this with other programs to check and it was consistent with programs I started/stopped.Code:Is msaccess.exe running: True Is firefox.exe running: True Is i_view32.exe running: False Is excel.exe running: False Is explore.exe running: False Is greenshot.exe running: True 'Started Excel here Is msaccess.exe running: True Is firefox.exe running: True Is i_view32.exe running: False Is excel.exe running: True Is explore.exe running: False Is greenshot.exe running: True
Is msaccess.exe running: True
Is firefox.exe running: False
Is i_view32.exe running: False
Is excel.exe running: False
Is Integrator.exe running: True
Is TDM.exe running: False
Is msaccess.exe running: True
Is firefox.exe running: False
Is i_view32.exe running: False
Is excel.exe running: False
Is Integrator.exe running: True
Is TDM.exe running: True
If I understand what you are asking, you can't. You can, as the others have shown you, determine whether Excel is running or not, but if the "file" excel is using is new, then it doesn't actually exist until you save it, so no file is actually "open".not one that is saved in a directory that is open, but one that is open as new, Book1, Book2, etc.
But what would be the point of doing that? What is it you are trying to determine?
Don't have other excel open or running while the program is running that's using Excel. Otherwise, it will corrupt the program.
tested the code again and it work - maybe a typo earlier. Thanks and Best !