MS Excel - Проверка - запущен или нет
Public Function IsExcelOpen() As Boolean
'Если MS Excel запущен - вернёт True (-1)
'--------------------------------------------------------------------
Dim objExcelApp As Object
'Dim objExcelApp As Excel.Application
On Error GoTo IsExcelOpenErr
Set objExcelApp = GetObject(, "Excel.Application")
objExcelApp.Visible = True
IsExcelOpen = True
IsExcelOpenBye:
On Error Resume Next
Set objExcelApp = Nothing
Exit Function
IsExcelOpenErr:
IsExcelOpen = False
Err.Clear
Resume IsExcelOpenBye
End Function
Пример эксплуотации:
Dim AppIsRunning As Boolean
AppIsRunning = IsExcelOpen
If AppIsRunning = False Then
Set objExcelApp = CreateObject("Excel.Application")
Else
Set objExcelApp = GetObject(, "Excel.Application")
End If
If AppIsRunning = False Then objExcelApp.Quit