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

    Activate Contacts (Wd XP VBA)

    From a Word macro, I need to activate Outlook Contacts if it's currently running. The following works well, most of the time:

    If Tasks.Exists("Contacts") Then
    Tasks("Contacts").Activate

    However, if the current session of Contacts is not "owned" by the current user (e.g. a secretary who has permission to her boss's and that Contacts folder is open), an error displays saying that Contacts cannot be activated.

    I suppose this is a Microsoft security safeguared, but it doesn't seem to make sense... if the current user has permission to the folder, WHICH IS A CURRENT TASK, why would it not be assumed that a macro should be able to activate that task?

    Is there a way around this, or perhaps there's a setting in Outlook that would not cause this error.

    Also, when starting Outlook fomr Word, is there a switch to cause it to open with Contacts as the view?

    Thanks
    Richard Barrett

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Activate Contacts (Wd XP VBA)

    I'm a newbie at Outlook, but this works for me in Office 97. There may still be a problem with your security issue that one of our Outlook gurus will have to tackle. You could also add another line to set the Contacts view to a standard (like address cards). HTH --Sam

    <pre>Option Explicit

    Sub viewContacts()

    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
    End Sub</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

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

    Re: Activate Contacts (Wd XP VBA)

    Thanks very much for your suggested code.

    The "security" problem ended up not being a problem at all. Although the symptoms looked like a logical problem -- access to "my" Contacts folder but not to those owned by others -- it couldn't be duplicated 24 hours later, and everything worked as expected. Go figure!

    Thanks again.
    Richard Barrett

  4. #4
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Activate Contacts (Wd XP VBA)

    Next time it happens tell them to grin and bear it. --Sam Barrett
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

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

    Re: Activate Contacts (Wd XP VBA)

    Hi Sam,

    I've just gotten around to testing the code you suggested. It won't compile for me in Word 97. The very first line causes an error.... "user defined type is not defined." Outlook.Application seems to be triggering that. Is this code that you wrote in Word? Did you attach a reference that I perhaps don't have attached?

    Thanks,
    Richard

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Activate Contacts (Wd XP VBA)

    You need to set a reference in Tools/References... to the Microsoft Outlook nn Object Model. The value of nn depends on the version of Outlook you're using.

    Usually, if you set the reference on a machine with an older version of Outlook, and then move to a machine with a newer version, the refererence will update itself. But if you set the reference on a machine with a newer version, and then move to a machine with an older version, you may get syntax errors. In that case, select Tools/References..., uncheck the MISSING reference, click OK, select Tools/References... again and check the correct reference.

Posting Permissions

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