Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Start Outlook from Word (VBA - Word 07)

    I have successfully used the code below with Word 2000, XP and 2003. My goal is to active Outlook Contacts if that Outlook folder is open. If Outlook is running, but Contacts is not visible, I start Outlook, with the Contact folder active. If Outlook is not running, I do the same. In Office 2007, this code does not create and display Outlook Contacts if Outlook was not already running. The code does active Outlook Contacts, if running, and it does add and active a Contacts folder if something else is currently active in Outlook. What must I do differently in 2007? For the moment, I have added the If construct at the end of the code (commented out).

    Thanks,
    Richard

    Sub GoToOutlookContacts()
    If Tasks.Exists("Contacts") Then
    Tasks("Contacts").Activate
    Tasks("Contacts").WindowState = wdWindowStateNormal
    Else
    Dim olApp As Outlook.Application
    Dim olNS As Outlook.NameSpace
    Dim olContacts As Outlook.MAPIFolder
    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")
    If olApp Is Nothing Then _
    Set olApp = CreateObject("Outlook.Application")
    olApp.Visible = True
    Set olNS = olApp.GetNamespace("MAPI")
    Set olContacts = olNS.GetDefaultFolder(olFolderContacts)
    olContacts.Display
    ' If Not Tasks.Exists("Contacts") Then
    ' MsgBox "Please start Outlook", vbInformation + vbOKOnly, "Outlook Integration"
    ' End If
    End If
    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Start Outlook from Word (VBA - Word 07)

    I'm not sure why Outlook 2007 would work differently. If you re-enable error checking after the GetObject line, perhaps you can capture some error information.

    (In my own case, I have Outlook set to present the "choose profile" dialog, which complicates any startup scenario.)

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Start Outlook from Word (VBA - Word 07)

    With error checking cleared, the object variable is not found. That would make sense, since the code is not succeeding.

    I found a suggestion online that "localhost" (with the quotes) be added as a parameter to CreateObject. I tried that. On the first run, Outlook Contacts opened as expected, but Word and the VBE locked up. On a later attempt, Outlook did not start, and my PC required a reboot.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Start Outlook from Word (VBA - Word 07)

    Does the "New" approach work any better? This alternate syntax is used in Automating Outlook from a Visual Basic Application [Outlook 2007 Developer Reference]:

    <code>Set olApp = New Outlook.Application</code>

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Start Outlook from Word (VBA - Word 07)

    That looked promising, but it raises an error: "The specified object could not be found." I removed the Outlook reference, saved, reattached the Outlook reference. Same error.

Posting Permissions

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