Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check if Outlook is Running from Word (Office XP)

    Using VBA in Word, I'm launching Outlook but if Outlook is already open, it launches another instance. How do I check if Outlook is already running so I don't launch it again? Thanks.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if Outlook is Running from Word (Office XP)

    There are several reliable ways to get this info. One easy way is to use the Tasks object in Word

    For each aTask in Application.Tasks
    if aTask.Name = "Microsoft Outlook" then
    msgbox "Outlook is running."
    endif
    Next

    Another way is to use an API call to FindWindow. There are others too.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    New Lounger
    Join Date
    Nov 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if Outlook is Running from Word (Office XP)

    thanks much Kevin. i didn't quite use what you gave me but it led me to Tasks.Exist which worked perfectly.

    now i have a new problem, if anyone can help. if any other app is not minimized, when i open outlook, it becomes the window with the focus but i need it to remind on the active document in word. any help would be appreciated. thanks again kevin

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if Outlook is Running from Word (Office XP)

    Show us your code that opens Outlook.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    New Lounger
    Join Date
    Nov 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if Outlook is Running from Word (Office XP)

    here's my code:

    If Tasks.Exists("Microsoft Outlook") = True Then
    GoTo continue
    Exit Sub
    Else
    retVal = Shell("outlook.exe", vbMinimizedNoFocus)
    Tasks("Microsoft Word").WindowState = wdWindowStateMaximized


    GoTo continue
    Exit Sub
    End If


    i have Word and PC DOCS open. It works fine if PC DOCs is minimized but if it's max or restored, it pops up front when the code opens Outlook

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if Outlook is Running from Word (Office XP)

    That's what I thought.

    Try using CreateObject instead; if Outlook is running, use GetObject

    dim olApp as Object

    Your code might then look like this:

    If not Tasks.Exists("Microsoft Outlook") then
    Set olApp = CreateObject("Outlook.Application")
    else
    Set olApp = GetObject("Outlook.Applicatoin")
    endif

    You can even dispense with the Tasks.Exist test if you want:

    Set olApp = Getobject(, "Outlook.Application")
    If Err.Number = 0 Then
    'Outlook is running
    Else
    'It's not
    endif
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    New Lounger
    Join Date
    Nov 2001
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Check if Outlook is Running from Word (Office XP)

    again much thanks. i'll try this when i get home and let you know how it worked. have a great weekend:

Posting Permissions

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