You can use the GetObject function to get the active instance of Excel. If no instance is found, an error is returned.
Code:
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
'Excel is not currently running
Err.Clear ' Clear Err object
Else
'Excel is running
End If
On Error GoTo ErrHndlr 'Send future errors to your error handling routine
Or, you can use the FindWindow API function.
Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
' If Excel is running this API call returns its handle.
hwnd = FindWindow("XLMAIN", 0)
If hwnd <> 0 Then ' Excel is running.
MsgBox "Please Close the Microsoft Excel Application Before Running This Program."
End If
Hope this helps!