Consulting

Results 1 to 5 of 5

Thread: Help - Outlook 2010 VBA script - Can't find Outlook contacts folder in object model

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jun 2019
    Posts
    3
    Location

    Help - Outlook 2010 VBA script - Can't find Outlook contacts folder in object model

    Using VBA macro scripting (Outlook 2010 on Windows 7) I am trying to programatically repair corrupted telephone numbers in an Outlook contacts subfolder (phone numbers appear duplicated in scientific notation rather than telephone formatting). This is my first time working with the Outlook Contacts object model and am having trouble finding (and binding to) the corrupted folder. This is how my local Contacts hierarchy appears in the folder explorer:

    MyContacts
    Contacts - University Outlook365 account < Primary email but no contact entries (don't use) Contacts - Private PST account < My primary contact list (lots of entries) Suggested Contacts - University Outlook365 < Historical email address only Suggested Contacts - Private PST account < Historical email address only Suggested Contacts - Private website A < No contacts Suggested Contacts - Private website B < No contacts Search results
    My university Outlook 365 address is what I primarily use for outgoing and incoming email, but for privacy purposes I use the local PST folder to store contact information. This is the corrupted contact folder (highlighted in bold) and the one I am trying to access and repair.

    I have been trying to bind to this folder using various VBA scripts, like the following, but no contact items are found. I suspect that my non-standard and hybrid O365/PST folder organization and inexperience with the Outlook object model may be to blame, but would appreciate any assistance or guidance from forum members with more experience in this area.

    Sub GetContactsFolder()
    
    Dim olNS As Outlook.NameSpace
    Dim xolContactFolder As Outlook.MAPIFolder
    Dim olContact As Outlook.ContactItem
    Dim olItems As Outlook.Items
    
    
    Set olNS = Application.GetNamespace("MAPI")
    Set xolContactFolder = olNS.GetDefaultFolder(olFolderContacts).Parent.Folders("Private PST account")
    Set olItems = xolContactFolder.Items
    
    
    For Each olContact In olItems
    
    
       'repair corrupted contacts
        Debug.Print olContact.FullName
    
    
    Next
    
    
    Set olItems = Nothing
    Set olNS = Nothing
    Set olContactFolder = Nothing
    Set olContact = Nothing
    
    
    End Sub
    * Note that the account folder names shown above are descriptive and fictitious for privacy

    In the above script, olItems.count is zero.
    Last edited by BGood; 06-26-2019 at 10:49 AM. Reason: typos

Tags for this Thread

Posting Permissions

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