none
Outlook 2016 vba macro to open a contact RRS feed

  • Question

  • Hi ...

    Since there is no way of opening a contact card in Outlook 2016 using start-up options, there's probably no way to do this through a macro once the program is opened either?

    Or is it?

    If so, is there an example of the code somewhere?

    In advance thanks

    Monday, October 3, 2016 11:57 AM

Answers

All replies

  • Hi,

    Since your question is related macro, I'm moving it to the dedicated Outlook for developer forum for further assistance:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Ethan Hua


    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, October 4, 2016 8:33 AM
  • Hello,

    Since there is no way of opening a contact card in Outlook 2016 using start-up options

    Of course, you need to run Outlook for that. Or just automate it from another application or script. See How to automate Outlook from another program for more information.  

    You can handle the Startup event of the Application class which is fired when Microsoft Outlook is starting, but after all add-in programs have been loaded. Also take a look at the Application.MAPILogonComplete event. It is fired after the user has logged onto the system.

    The Display method of the ContactItem class displays a new Inspector object for the item. To activate an explorer or inspector window, use the Activate method. You may find the How To: Create a new Outlook Contact item programmatically article helpful. 


    [custom.development]

    • Proposed as answer by David_JunFeng Friday, October 14, 2016 9:37 AM
    • Marked as answer by David_JunFeng Monday, October 17, 2016 2:35 PM
    Tuesday, October 4, 2016 12:22 PM
  • Hi Rypdaling,

    According to your description, you could refer to below code:

    Private Sub Application_Startup()
    
        Dim Ns As Outlook.NameSpace
    
        Set Ns = Application.GetNamespace("MAPI")
    
        Dim myItems As Outlook.Items
    
        Set myItems = Ns.GetDefaultFolder(olFolderContacts).Items
    
        Dim myRestrictItems As Outlook.Items
    
        Set myRestrictItems = myItems.Restrict("[FullName] = 'Jack'")
    
        myRestrictItems(1).Display
    
    End Sub

    The result:

    Thanks for your understanding.

                          
    Wednesday, October 5, 2016 6:59 AM
  • I get an error in the last line

    myRestrictItems(1).Display

    A message box saying; Run-time error '440': Datatable is outside limits.

    Freely translated from norwegian. :-)

    How can this be fixed?

    thank you ...

    Friday, November 30, 2018 5:08 AM
  • Looks like no one replied.  I've not tested, but from memory.. this is a 0 based array,

    myRestrictItems(0).Display

    Also if no items were found then it could have caused an issue.. again not tested but:

    if myRestrictItems.count > 0 then

    myRestrictItems(0).Display

    end if

    I know this is an old thread but maybe this will help someone


    • Edited by sidupac Monday, November 9, 2020 3:38 AM
    Monday, November 9, 2020 3:37 AM