Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1585
  • Last Modified:

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

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.

reneleisibach
0
reneleisibach
Asked:
reneleisibach
  • 2
2 Solutions
 
Chris BottomleyCommented:
See http://www.experts-exchange.com/Q_22875757.html

i.e:

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)
    Else
        dummy = SetForegroundWindow(Find_App)
    End If
End Sub

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

Chris
0
 
Ryan ChongCommented:
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
            outlookApp.Explorers.Item(1).Display
            outlookApp.Explorers.Item(1).Activate
        End If
    Else
        Shell "Outlook", vbNormalFocus
    End If
End Sub
0
 
Ryan ChongCommented:
just found that this line is not necessary:

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


hope this helps, cheers
0
 
reneleisibachAuthor Commented:
Both solutions work very well.

Thank you both

reneleisibach
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now