Solved

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

Posted on 2013-05-31
3
901 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

735 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