Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking if outlook is open

Status
Not open for further replies.

spizotfl

MIS
Aug 17, 2005
345
US
hi, i used the example laid out in faq702-2921 and it works lovely for me. the way it is set up, it would appear that it creates an outlook instance, sends the message, and then closes outlook. what i would like to do is check and see if outlook is already open and then leave it open after the email has been sent. i am sure there is probably a fairly simple way to do this, but i haven't come across it looking in the help files or in the books that i have.
i appreciate any help....

"Maturity is a bitter disappointment for which no remedy exists, unless laughter can be said to remedy anything."
-Vonnegut
 
Dim booWasOpen As Boolean
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.application")
If Err Then
Set objOutlook = CreateObject("Outlook.application")
booWasOpen = False
Err.Clear
Else
booWasOpen = True
End If
On Error GoTo 0
Set objEmail = objOutlook.CreateItem(olMailItem)
...
If Not booWasOpen Then objOutlook.Quit
Set objEmail = Nothing
Set objOutlook = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
This works in Windows XP and Office 2k.
Code:
Public Sub TestForOutLook()
On Error Resume Next
Dim objOutlook As Object
Set objOutlook = GetObject(, "Outlook.application")
If Err.Number = 429 Then
  Set objOutlook = CreateObject("Outlook.application")
End If
'Your code here
'...
Set objOutlook = Nothing
End Sub

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top