Start Outlook with VBA, if/when started, then make it active

Posted on 2007-10-16
Last Modified: 2013-11-27
How can Outlook be started with Access-VBA code. If the program is already started then I would like to make it active (put the program as active window).

In advance thank you for your help.

Question by:reneleisibach
    LVL 59

    Accepted Solution



    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

    Sub ol_open()
    Dim dummy As Double
        If Find_App = 0 Then
            dummy = Shell("Outlook.exe", vbNormalFocus)
            dummy = SetForegroundWindow(Find_App)
        End If
    End Sub

    Function Find_App() As Long
        Find_App = FindWindow(vbNullString, "Microsoft Outlook")
    End Function

    LVL 48

    Assisted Solution

    by:Ryan Chong
    or without API, try this:

    Private Sub Command0_Click()
        Dim outlookApp As Object
        On Error Resume Next
        Set outlookApp = GetObject(, "Outlook.Application")
        On Error GoTo 0
        If Not outlookApp Is Nothing Then
            If outlookApp.Explorers.Count > 0 Then
            End If
            Shell "Outlook", vbNormalFocus
        End If
    End Sub
    LVL 48

    Expert Comment

    by:Ryan Chong
    just found that this line is not necessary:

    outlookApp.Explorers.Item(1).Display '<< remove this from above sample.

    hope this helps, cheers

    Author Comment

    Both solutions work very well.

    Thank you both


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now