Solved

Loop with VBA through Outlook 2007 contacts stored on a different .pst

Posted on 2013-05-31
3
904 Views
Last Modified: 2013-05-31
We have our contacts stored on a separate .pst which has nothing else other than contacts and the default stuff MS places on every pst. This is so we can synchronize out contacts here with a simple copy/paste script.

However, I can't seem to find a way to loop through the contacts using VBA for mass editing. I can loop through the default pst contacts, but those are empty.

Anyone knows how I can achieve this, please?
0
Comment
Question by:Cluskitt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 39210617
Hi, Cluskitt.

I'm assuming that you're familiar with VBA and using something like

Set olkFolder = Session.GetDefaultFolder(olFolderContacts)

Open in new window


to get the Contacts folder.  If so, then you can add this function to your code to get any folder via its path.

Public Function OpenOutlookFolder(strFolderPath As String) As Outlook.MAPIFolder
    ' Purpose: Opens an Outlook folder from a folder path.
    ' Written: 4/24/2009
    ' Author:  David Lee
    ' Outlook: All versions
    Dim arrFolders As Variant, _
        varFolder As Variant, _
        bolBeyondRoot As Boolean
    On Error Resume Next
    If strFolderPath = "" Then
        Set OpenOutlookFolder = Nothing
    Else
        Do While Left(strFolderPath, 1) = "\"
            strFolderPath = Right(strFolderPath, Len(strFolderPath) - 1)
        Loop
        arrFolders = Split(strFolderPath, "\")
        For Each varFolder In arrFolders
            Select Case bolBeyondRoot
                Case False
                    Set OpenOutlookFolder = Outlook.Session.Folders(varFolder)
                    bolBeyondRoot = True
                Case True
                    Set OpenOutlookFolder = OpenOutlookFolder.Folders(varFolder)
            End Select
            If Err.Number <> 0 Then
                Set OpenOutlookFolder = Nothing
                Exit For
            End If
        Next
    End If
    On Error GoTo 0
End Function

Open in new window


To use this you'll call it like this

Set olkFolder = OpenOutlookFolder("Some Folder Path")

Open in new window


For example, if the folder is in a PST file called "Personal Folders" and is called "Contacts" then the path would be "Personal Folders\Contacts".
0
 
LVL 18

Author Comment

by:Cluskitt
ID: 39210663
I did stumble upon that piece of code, or something similar, but couldn't get it to work properly.

If I use the path (to continue with that example): "Personal Folders\Contacts\Contacts1" I do get an item count. But if I simply use "Personal Folders\Contacts", the item count is 0.

I want to loop all the folders inside contacts. Going through them one by one kinda defeats the purpose.

And yes, you can assume a decent VBA knowledge. :)
0
 
LVL 18

Author Closing Comment

by:Cluskitt
ID: 39210692
Nevermind, got it working. I just had to make create another loop outside the items loop to cycle through the subfolders. Thanks for the help.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question