justagrunt
Technical User
- Oct 10, 2002
- 132
Hi,
Automating an email but found that .quit etc closed the already running session, so tried the following only to get an error 48 - Object doesn't support this property or method.
Is it possible to check for a already running instance use it but not destroy it or if not, create and then close.
Dim fisOutlookrunning As Boolean
'create variables for Outlook
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'create an Outlook instance to use for the email message: uses
'the existing Outlook instance if there is one, otherwise creates
'a new instance.
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
fisOutlookrunning = False
'Outlook is not running; create an Outlook object
Set objOutlook = CreateObject("Outlook.Application")
Err.Clear
Else
'use current Outlook object
fisOutlookrunning = True
End If
Set objEmail = objOutlook.CreateItem(olMailItem)
'Sets up error handler for the rest of the procedure
On Error GoTo Err_messageError
'close Outlook
Set objEmail = Nothing
' quit the instance of Outlook in use.
objOutlook.Quit
Set objOutlook = Nothing
Err_messageError:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
End Sub
Warm Regards
Bill
Automating an email but found that .quit etc closed the already running session, so tried the following only to get an error 48 - Object doesn't support this property or method.
Is it possible to check for a already running instance use it but not destroy it or if not, create and then close.
Dim fisOutlookrunning As Boolean
'create variables for Outlook
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
'create an Outlook instance to use for the email message: uses
'the existing Outlook instance if there is one, otherwise creates
'a new instance.
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
fisOutlookrunning = False
'Outlook is not running; create an Outlook object
Set objOutlook = CreateObject("Outlook.Application")
Err.Clear
Else
'use current Outlook object
fisOutlookrunning = True
End If
Set objEmail = objOutlook.CreateItem(olMailItem)
'Sets up error handler for the rest of the procedure
On Error GoTo Err_messageError
'close Outlook
Set objEmail = Nothing
' quit the instance of Outlook in use.
objOutlook.Quit
Set objOutlook = Nothing
Err_messageError:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
End Sub
Warm Regards
Bill