I am trying to have a msgbox state in the title the name of the Microsoft application that is being checked and then in the msgbox state true or false. Currently everything works properly except the title of the msgbox it will not put the application name. Here is the code that i have currently.
This part is on the form for button click to start the process. it then calls IsAppRunning in the next part of the code. Could someone help me figure this out. Thank you in advance.
Code:
Option Compare Database
Option Explicit
Dim appString As String
Private Sub btnGetAttach_Click()
MsgBox IsAppRunning(1), , (appString & ".application")
MsgBox IsAppRunning(6), , (appString & ".application")
MsgBox IsAppRunning(3), , (appString & ".application")
MsgBox IsAppRunning(6), , (appString & ".application")
End Sub
Code:
Option Compare Database
Public Enum OfficeAppName
' enums always start from zero, unless otherwise specified
' for demonstration purposes (on the worksheet), start from 1
OutLook = 1
PowerPoint = 2
Excel = 3
Word = 4
Publisher = 5
Access = 6
End Enum
Function IsAppRunning(appName As OfficeAppName) As Boolean
'End Function
' check if a particular Office app is running
On Error GoTo NotRunning
Dim officeApp As Object
Dim appString As String
' assume true
IsAppRunning = True
' determine which app is being checked
Select Case appName
Case 1 ' Outlook
appString = "Outlook"
Case 2 ' PowerPoint
appString = "PowerPoint"
Case 3 ' Excel
appString = "Excel"
Case 4 ' Word
appString = "Word"
Case 5 ' Publisher
appString = "Publisher"
Case 6 ' Access
appString = "Access"
End Select
' try to hook into existing object
Set officeApp = GetObject(, appString & ".Application")
ExitProc:
Exit Function
NotRunning:
IsAppRunning = False
Resume ExitProc
End Function