View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Sean Sean is offline
external usenet poster
 
Posts: 454
Default Check to see if Outlook is open Q

On Oct 13, 5:14 pm, "Chip Pearson" wrote:
Try something like the following. It will latch onto an existing instance of
Outlook if one exists. Otherwise, it will create a new instance. If the code
creates a new instance, it will Quit that instance when done. An existing
instance is left running and undisturbed.

Sub AAA()
Dim OLKApp As Outlook.Application
Dim WeStartedIt As Boolean

On Error Resume Next
Set OLKApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If OLKApp Is Nothing Then
Set OLKApp = CreateObject("Outlook.Application")
If OLKApp Is Nothing Then
' can't create app
' error mesage then exit
MsgBox "Can't Get Outlook"
Exit Sub
End If
WeStartedIt = True
Else
WeStartedIt = False
End If
''''''''''''''''''''''''''''''
' your code here
''''''''''''''''''''''''''''''
If WeStartedIt = True Then
OLKApp.Quit
End If
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consultingwww.cpearson.com
(email on the web site)

"Sean" wrote in message

oups.com...



Thanks Jim, your code works good, however if I wanted to leave Outlook
open instead of closing it when my macro finished, how would I do that
I tried removing olApp.Quit, thinking this is what closes Outlook, but
it still closed regardless or possibly the option for Outlook to
remain open for 2 mins (so send/receive can work) before closing


I've also tested it with an instance of Outlook alraedy open and it
doesn't open a 2nd instance nor does it close the 1st instance, which
is what I'd want to happen


Thanks- Hide quoted text -


- Show quoted text -


Thanks guys, my problem is that Outlook closes before send/receive is
actioned, thus my mail remains in the Outbox, how do I delay the
closing of Outlook for say 60 seconds