PC Review


Reply
Thread Tools Rate Thread

Check to see if Outlook is open Q

 
 
Sean
Guest
Posts: n/a
 
      13th Oct 2007
How would I check to see if Oulook is open and if it isn't open an
instance of it?

I ask in this NG as I have a routine in Excel that e-mails out a file
and it is within this code I wish to include this check/action

Thanks

 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      13th Oct 2007

From the Office XP Developer code library...
' Because Outlook is a multi-use COM component, if Outlook is not running,
' initializing an object variable to work with the Application object creates a
' new hidden instance. But if Outlook is already running, initializing the object
' variable returns a reference to the running instance.
'---
Dim olApp As Outlook.Application
Set olApp = New Outlook.Application
With olApp
' Code to automate Outlook here.
End With
olApp.Quit
Set olApp = Nothing
'---

If Outlook is not installed, the above might get pretty interesting.<g>
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Sean"
wrote in message
How would I check to see if Oulook is open and if it isn't open an
instance of it?
I ask in this NG as I have a routine in Excel that e-mails out a file
and it is within this code I wish to include this check/action
Thanks

 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      13th Oct 2007
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



 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      13th Oct 2007

It may be open and running and you just can't see it...
When a new instance is opened, it is invisible (as the notes stated).
Look in Task Manager to confirm.
If you want to see it, use olApp.Visible = True
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Sean" <(E-Mail Removed)>
wrote in message
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



 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      13th Oct 2007
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 Consulting
www.cpearson.com
(email on the web site)


"Sean" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>


 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      13th Oct 2007
On Oct 13, 5:14 pm, "Chip Pearson" <c...@cpearson.com> 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" <seanrya...@yahoo.co.uk> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > 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

 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      13th Oct 2007
On Oct 13, 5:09 pm, "Jim Cone" <jim.cone...@rcn.comXXX> wrote:
> It may be open and running and you just can't see it...
> When a new instance is opened, it is invisible (as the notes stated).
> Look in Task Manager to confirm.
> If you want to see it, use olApp.Visible = True
> --
> Jim Cone
> San Francisco, USAhttp://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)
>
> "Sean" <seanrya...@yahoo.co.uk>
> wrote in message
> 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


Jim, I used olApp.Visible = True but it debugs on this line (object
doesn't support this object or method), do I have to set any
references?. I entered as-:

Dim olApp As Outlook.Application
Set olApp = New Outlook.Application
With olApp
olApp.Visible=True
' Code to automate Outlook here.
End With
olApp.Quit
Set olApp = Nothing

 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      13th Oct 2007

Sean,
It looks like I fed you some bogus information. From the "technet/scriptcenter"...
"...Note that this is different from other Office programs; in Word or Excel, for example, you create an instance of the Application
object and then set the Visible property to True. That's not how things are done in Outlook. Here we bind to a namespace and a
folder, then call the Display method to make our folder - and the rest of Outlook - visible...."
The rest of the post is here...
http://www.microsoft.com/technet/scr.../tips0614.mspx
Looks like you have some work to do. <g>
Jim Cone


"Sean"
wrote in message
On Oct 13, 5:09 pm, "Jim Cone wrote:
> It may be open and running and you just can't see it...
> When a new instance is opened, it is invisible (as the notes stated).
> Look in Task Manager to confirm.
> If you want to see it, use olApp.Visible = True
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)



Jim, I used olApp.Visible = True but it debugs on this line (object
doesn't support this object or method), do I have to set any
references?. I entered as-:

Dim olApp As Outlook.Application
Set olApp = New Outlook.Application
With olApp
olApp.Visible=True
' Code to automate Outlook here.
End With
olApp.Quit
Set olApp = Nothing

 
Reply With Quote
 
Sean
Guest
Posts: n/a
 
      14th Oct 2007
I've got the following code which appears to work except for the
following issues:-

1) The Copy_Paste macro it calls produces an e-mail which remain's in
Outlooks outbox until I open the application manually. Thus it appears
the code below closes Outlook before send/receive is actioned, however
I do have the option checked in Outlook where it does a send/receive
on application close, so not sure why it doesn't go

2) Within my Task Manager, although there are no application shown,
there is an Outlook.exe process that remains, so if I open Outlook
manually after the code below is run I have 2 Outlook processes. Does
this cause an issues? Doesn't look right to me


Option Explicit
Sub Auto_Open()
Application.ScreenUpdating = False
Application.WindowState = xlMinimized

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


Dim OkToCallMacro As Boolean
OkToCallMacro = False
Select Case Weekday(Date)
Case vbMonday To vbFriday
If Time >= TimeSerial(8, 44, 0) _
And Time < TimeSerial(8, 46, 0) Then
OkToCallMacro = True
End If
Case Is = vbSaturday, vbSunday
If Time >= TimeSerial(10, 18, 0) _
And Time < TimeSerial(10, 20, 0) Then
OkToCallMacro = True
End If
End Select

If OkToCallMacro Then
Call Copy_Paste

If Workbooks.Count = 1 Then
'only this workbook is open
ThisWorkbook.Save
'close the application
'(which will close thisworkbook)
Application.Quit
Else
ThisWorkbook.Close savechanges:=True
End If
End If

If WeStartedIt = True Then
OLKApp.Quit
End If


End Sub

 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      14th Oct 2007

Sean,

Your questions should really be directed to an Outlook newsgroup.
I pretend to know something about Excel but Outlook is an undiscovered country.
Nevertheless...

Re: Item 1 - review the technet link again - note that it says...
"...If Outlook isn't running, however, you'll need to call the Logon method
and log on before your script can do anything..."

Re: Item 2 - set all object references to Nothing...
Set OLKApp = Nothing
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Sean" <(E-Mail Removed)>
wrote in message
I've got the following code which appears to work except for the
following issues:-

1) The Copy_Paste macro it calls produces an e-mail which remain's in
Outlooks outbox until I open the application manually. Thus it appears
the code below closes Outlook before send/receive is actioned, however
I do have the option checked in Outlook where it does a send/receive
on application close, so not sure why it doesn't go

2) Within my Task Manager, although there are no application shown,
there is an Outlook.exe process that remains, so if I open Outlook
manually after the code below is run I have 2 Outlook processes. Does
this cause an issues? Doesn't look right to me

Option Explicit
Sub Auto_Open()
Application.ScreenUpdating = False
Application.WindowState = xlMinimized

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

Dim OkToCallMacro As Boolean
OkToCallMacro = False
Select Case Weekday(Date)
Case vbMonday To vbFriday
If Time >= TimeSerial(8, 44, 0) _
And Time < TimeSerial(8, 46, 0) Then
OkToCallMacro = True
End If
Case Is = vbSaturday, vbSunday
If Time >= TimeSerial(10, 18, 0) _
And Time < TimeSerial(10, 20, 0) Then
OkToCallMacro = True
End If
End Select

If OkToCallMacro Then
Call Copy_Paste

If Workbooks.Count = 1 Then
'only this workbook is open
ThisWorkbook.Save
'close the application
'(which will close thisworkbook)
Application.Quit
Else
ThisWorkbook.Close savechanges:=True
End If
End If

If WeStartedIt = True Then
OLKApp.Quit
End If

End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My Outlook programme doesn't open and I can't check my emails! =?Utf-8?B?TU0=?= Microsoft Outlook Discussion 1 24th May 2007 11:36 PM
Mail check without Outlook fully open? Julius T. Microsoft Outlook 1 16th Nov 2005 03:18 AM
Outlook Can't Check email and Outlook Express Won't open Matt Harmon Microsoft Outlook 0 2nd Jul 2004 10:23 PM
Outlook Can't Check email and Outlook Express Won't open Matt Harmon Microsoft Outlook Discussion 0 2nd Jul 2004 10:23 PM
how can I check if outlook is already open and running in VB6? Mark Microsoft Outlook Form Programming 1 14th May 2004 02:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:42 AM.