J
John
Hello All,
I’d like to determine if Outlook 2002 is open when a procedure running
in Access, Excel, etc. attempts to send an email message so that I can
decide whether to close Outlook after the message is sent because the
user didn’t have it open or leave the instance running because the
user started it. Without examining running processes, the best I came
up with is to catch error 462 ‘The remote server machine does not
exist or is unavailable.’ after attempting to access a property of the
application object variable having set it to Outlook.Application. If
the error is thrown, I set the object variable to New
Outlook.Application and store this fact away for when it comes time
decide whether to use the Quit method of the application object. Is
there a better way to do this? To make my method more clear, the
source for a wrapper class I use to do this follows.
Thanks.
Option Explicit
Private molkApp As Outlook.Application
Private mfIsNew As Boolean
'olkApp
Public Property Get olkApp() As Outlook.Application
Set olkApp = molkApp
End Property
'Initialize
Private Sub Class_Initialize()
On Error GoTo Error
Const bytcDoingNothing As Byte = 0
Const bytcDoingCheckGet As Byte = 1
Dim bytDoing As Byte
Dim strName As String
Set molkApp = Outlook.Application
bytDoing = bytcDoingCheckGet
strName = molkApp.Name
GoTo ExitProcedure
NewApp:
bytDoing = bytcDoingNothing
Set molkApp = New Outlook.Application
mfIsNew = True
ExitProcedure:
On Error GoTo 0
Exit Sub
Error:
Select Case bytDoing
Case bytcDoingCheckGet
Select Case Err.Number
Case 462 'The remote server machine does not exist or
is unavailable.
Resume NewApp
Case Else
With Err
.Raise .Number, .Source, .Description, .HelpFile, .HelpContext
End With
End Select
Case Else
With Err
.Raise .Number, .Source, .Description, .HelpFile, .HelpContext
End With
End Select
End Sub
'Terminate
Private Sub Class_Terminate()
If mfIsNew Then
molkApp.Quit
End If
End Sub
I’d like to determine if Outlook 2002 is open when a procedure running
in Access, Excel, etc. attempts to send an email message so that I can
decide whether to close Outlook after the message is sent because the
user didn’t have it open or leave the instance running because the
user started it. Without examining running processes, the best I came
up with is to catch error 462 ‘The remote server machine does not
exist or is unavailable.’ after attempting to access a property of the
application object variable having set it to Outlook.Application. If
the error is thrown, I set the object variable to New
Outlook.Application and store this fact away for when it comes time
decide whether to use the Quit method of the application object. Is
there a better way to do this? To make my method more clear, the
source for a wrapper class I use to do this follows.
Thanks.
Option Explicit
Private molkApp As Outlook.Application
Private mfIsNew As Boolean
'olkApp
Public Property Get olkApp() As Outlook.Application
Set olkApp = molkApp
End Property
'Initialize
Private Sub Class_Initialize()
On Error GoTo Error
Const bytcDoingNothing As Byte = 0
Const bytcDoingCheckGet As Byte = 1
Dim bytDoing As Byte
Dim strName As String
Set molkApp = Outlook.Application
bytDoing = bytcDoingCheckGet
strName = molkApp.Name
GoTo ExitProcedure
NewApp:
bytDoing = bytcDoingNothing
Set molkApp = New Outlook.Application
mfIsNew = True
ExitProcedure:
On Error GoTo 0
Exit Sub
Error:
Select Case bytDoing
Case bytcDoingCheckGet
Select Case Err.Number
Case 462 'The remote server machine does not exist or
is unavailable.
Resume NewApp
Case Else
With Err
.Raise .Number, .Source, .Description, .HelpFile, .HelpContext
End With
End Select
Case Else
With Err
.Raise .Number, .Source, .Description, .HelpFile, .HelpContext
End With
End Select
End Sub
'Terminate
Private Sub Class_Terminate()
If mfIsNew Then
molkApp.Quit
End If
End Sub