TIA
If objOutlook Is Nothing Then
MsgBox "Outlook not running"
Else
MsgBox "Outlook is running"
End If
End Sub
Regards,
Tom Ogilvy
DFStoneJr <DFSt...@NOSPAM.yahoo.com> wrote in message
news:uvg3b9f...@corp.supernews.com...
TIA.
"Tom Ogilvy" <twog...@msn.com> wrote in message news:<OZ4UBgZoCHA.2224@TK2MSFTNGP11>...
If objOutlook Is Nothing Then
set objOutlook = CreateObject("Outlook.Application")
End If
' objOutlook should now hold a reference to a running instance of Outlook
End Sub
Untested, but should work.
Regards,
Tom Ogilvy
DFStoneJr <DFSt...@yahoo.com> wrote in message
news:26cf567e.02121...@posting.google.com...
I'd like for the code to first test whether Outlook is running. Based
on the first response you gave, which returned a message indicating
Outlook's status, it does that. But I also want th code to run
Outlook if the result of the test indicates that Outlook is not
running. In the second response you provide, I can see where the line
"set objOutlook = CreateObject("Outlook.Application")" sets the
variable objOutlook, but I can't see that anything is doen with the
variable once it's set. What am I missing?
Thanks for your help and patience.
"Tom Ogilvy" <twog...@msn.com> wrote in message news:<eZiMM4koCHA.2636@TK2MSFTNGP10>...
Sub TestforOutlook()
'Dim objOutlook As Outlook.Application
'Dim objOutlookMsg As Outlook.MailItem
'Dim objOutlookRecip As Outlook.Recipient
'Dim objOutlookAttach As Outlook.Attachment
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object
Dim DisplayMsg As Boolean
Dim AttachmentPath As String
AttachmentPath = "C:\Data\message.txt"
DisplayMsg = True
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
End If
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Ogilvy, Thomas")
objOutlookRecip.Type = 1 'olTo
' Add the CC recipient(s) to the message.
'Set objOutlookRecip = .Recipients.Add("Michael Suyama")
'objOutlookRecip.Type = 2 'olCC
' Add the BCC recipient(s) to the message.
' Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
'objOutlookRecip.Type = 3 'olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." & vbCrLf & vbCrLf
.Importance = 2 'olImportanceHigh 'High importance
' Add attachments to the message.
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Send
End If
End With
set objOutlookMsg = nothing
set objOutlookRecip = nothing
set objOutlookAttach = nothing
Set objOutlook = Nothing
End Sub
Regards,
Tom Ogilvy
"DFStoneJr" <DFSt...@yahoo.com> wrote in message