Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 5 of 5

Thread: Is Outlook Open

  1. #1
    Join Date
    27th July 2007
    Posts
    3

    Is Outlook Open

    How to check from Excel VBA if Outlook is open and running?
    This was an old question with post http://www.ozgrid.com/forum/showthread.php?t=44790
    It was not closed with any answer or solution. I had the same problem so here is a little trick to solve it. Code works, but I just don't like how it looks like.

    If you have a better solution please post it here. There is not one good examle on the web.
    I'm sure there must be something like:
    IF NOT Application(Outlook).Open Then Open it .....

    VB:
     '*****************************************************************
     ' ?? IS OUTLOOK RUNNING ??
     ' 7/24/07 by Dusan J.
     '
     ' Problem:  To download attachment we need Outlook to be open.
     '   I didn't know how to check for open application so
     '   I used a little trick to solve this.
     ' Solution: Try to make Outlook Application active window.
     '   If Oulook is not open, that generates Run time error 91.
     '   On Error run a code to open Outlook.
     '******************************************************************
    Sub CheckIfOutlookIsRunning() 
        On Error Goto OutlookIsNotRunning 
        AppActivate ("Outlook") 
        Exit Sub 
         
    OutlookIsNotRunning: 
         '    Dim OutlookErr, OutlookBox
         '    OutlookErr = "This program requires Outlook to be running on your computer." & vbCrLf & vbCrLf
         '    OutlookErr = OutlookErr & "Please open Outlook and try again."
         '    OutlookBox = MsgBox(OutlookErr, vbCritical, "Outlook Is Not Open")
         ' Instead of Error message just open Outlook
        Call Open_OutLook 
        End 
    End Sub 
     '
    Sub Open_OutLook() 
        Dim oOutlook As Object 
        Dim oNameSpace As Object 
        Dim oInbox As Object 
         
        Set oOutlook = CreateObject("Outlook.Application") 
        Set oNameSpace = oOutlook.GetNamespace("MAPI") 
        Set oInbox = oNameSpace.Folders(1) 
         'Set oInbox = oInbox.Folders("Inbox")
        oInbox.Display 
         'oOutlook.Quit 'Close All Outlook copies
    End Sub 
     '---------------------------------------------------------
    
    

    Auto Merged Post;

    Doe's anyone has a real code/solution for something like this?
    Last edited by dusanj; July 27th, 2007 at 06:00. Reason: Auto Merged Doublepost

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    24th December 2004
    Location
    Nanaimo, Vancouver Island, British Columbia, Canada
    Posts
    2,464

    Re: Is Outlook Open

    Quote Originally Posted by dusanj
    ...Code works, but I just don't like how it looks like.

    ...I'm sure there must be something like:
    IF NOT Application(Outlook).Open Then Open it .....
    This is essentially an If Not open then open it.. Anyway it _looks_ better <G>


    VB:
    Sub CIOIR() 
         
        Dim oOutlook As Object 
        Dim oNameSpace As Object 
        Dim oInbox As Object 
         
        Set oOutlook = CreateObject("Oulook.Application") 
        Set oNameSpace = oOutlook.GetNamespace("MAPI") 
        Set oInbox = oNameSpace.Folders(1) 
         
         
         'Handle errors
        Err.Clear 'JIC
        On Error Resume Next 
         
         'attempt
        AppActivate ("Outlook") 
         
        If Err <> 0 Then oInbox.Display 
         
         'reset
        Err.Clear 
        On Error Goto 0 
         
         'cleanup
        Set oInbox = Nothing 
        Set oOutlook = Nothing 
        Set oNameSpace = Nothing 
         
    End Sub 
    
    
    Cheers,

    dr

    "Questions, help and advice for free, small projects by donation. large projects by quote"

    http://www.ExcelVBA.joellerabu.com

  3. #3
    Join Date
    27th July 2007
    Posts
    3

    Re: Is Outlook Open

    OK, cleaner code but ...
    - You have typo; missing "t" in ("Oulook.Application")
    - Also if Outlook is Open your code opens another copy of outlook. It would be nice not to do that.

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    24th January 2003
    Location
    Australia
    Posts
    31,705

  5. #5
    Join Date
    27th July 2007
    Posts
    3

    Re: Is Outlook Open

    After thinking about this more I fond the least amount of code I can use. I don't have to check if outllok is open; just close it first (if it is closed this doesn't genereta any error), and than open it. Here is all code you need. I don't know what kind of Error I can expect.

    VB:
    Sub Open_OutLook() 
        Dim oOutlook As Object 
        Dim oNameSpace As Object 
        Dim oInbox As Object 
         
        Set oOutlook = CreateObject("Outlook.Application") 
        Set oNameSpace = oOutlook.GetNamespace("MAPI") 
        Set oInbox = oNameSpace.Folders(1) 
         
        oOutlook.Quit 'Close All Outlook copies if open
        oInbox.Display 'Open/show Outlook
         
    End Sub 
    
    

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Open Already Existing Outlook Email
    By Quickdood in forum Excel and/or Email Help
    Replies: 3
    Last Post: July 12th, 2006, 01:58
  2. Open a discussion in Outlook 2000
    By Biz in forum Excel and/or Email Help
    Replies: 1
    Last Post: March 21st, 2006, 16:05
  3. Open Outlook if not open
    By ascalese in forum Excel and/or Email Help
    Replies: 2
    Last Post: November 19th, 2004, 03:55
  4. Open Outlook Mail after click on button
    By w00t111 in forum Excel and/or Email Help
    Replies: 4
    Last Post: November 12th, 2004, 06:52
  5. Open IMAP Folder in Outlook
    By StrongSteve in forum Excel and/or Email Help
    Replies: 1
    Last Post: August 3rd, 2004, 23:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno