Outlook 2007 - VBA to copy Public Folder contacts between folders and clear certain fields

Im looking for a VBA script that can be run from a Windows XP (with Office 2007) workstation that will do the following:

1  Erase all the contact items under the Public Folder called Rolodex (but not the folder itself)
2  Copy all the contact items from the Public Folder called Rolodex-Private to Rolodex
3  Erase the following fields from the contacts in Rolodex:  Category, Home Address & Notes (or simply not copy those fields)

Ive seen a few different solutions online that do similar things but nothing that comes close enough for me, with my limited programming skills, to figure out how to adapt for my uses.

Im under the gun with several projects at once here and hopefully someone will have a complete & easy solution for this!


(The most similar solution Ive found is http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_22125021.html but it deletes the entire folder instead of just the contents and also doesnt show how to erase data from specific contact fields)
RentANerdsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Hi, RentANerds.

This should do what you've described.  I haven't tested it, so please be sure to back up the data in both folders before you run this for the first time.  Follow these instructions to use the code.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor

Sub CopyPFContacts()
    Dim olkSource As Outlook.Folder, _
        olkTarget As Outlook.Folder, _
        olkItem As Outlook.ContactItem, _
        olkCopy As Outlook.ContactItem, _
        intIndex As Integer
    Set olkSource = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Rolodex-Private")
    Set olkTarget = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Rolodex")
    'Delete all items from the Rolodex folder'
    For intIndex = olkTarget.Items.Count To 1 Step -1
        olkTarget.Items.Item(intIndex).Delete
    Next
    'Copy all items from the source folder to the target folder while removing the requested fields'
    For Each olkItem In olkSource.Items
        Set olkCopy = olkItem.Copy
        With olkCopy
            .Categories = ""
            .HomeAddress = ""
            .Body = ""
            .Save
            .Move olkTarget
        End With
    Next
    Set olkSource = Nothing
    Set olkTarget = Nothing
    Set olkItem = Nothing
    Set olkCopy = Nothing
    MsgBox "Finished.", vbInformation + vbOKOnly, "Copy Public Folder Contacts"
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RentANerdsAuthor Commented:
The code worked FANTASTIC on the first try!  Thank-you VERY MUCH FOR IT!
0
David LeeCommented:
You're welcome.  Happy I could help.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

arjanpcCommented:
Hello, this script work for me to but i don't want to delete the contacts in the target map, because i want to overwrite them, becaue i have no scripting knowledge how do you change the script that way that the contacts from the target folder will me overwrited instead of deleted?
0
RentANerdsAuthor Commented:
I'm not sure if this will overwrite or duplicate ... and don't have time to test this morning...  (my gut feeling is that it may the duplicate)

But here is the same code that simply lacks the delete portion.  Let us know what happens.
Sub CopyPFContacts()
    Dim olkSource As Outlook.Folder, _
        olkTarget As Outlook.Folder, _
        olkItem As Outlook.ContactItem, _
        olkCopy As Outlook.ContactItem, _
        intIndex As Integer
    Set olkSource = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Rolodex-Private")
    Set olkTarget = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Rolodex")
    'Copy all items from the source folder to the target folder while removing the requested fields'
    For Each olkItem In olkSource.Items
        Set olkCopy = olkItem.Copy
        With olkCopy
            .Categories = ""
            .HomeAddress = ""
            .Body = ""
            .Save
            .Move olkTarget
        End With
    Next
    Set olkSource = Nothing
    Set olkTarget = Nothing
    Set olkItem = Nothing
    Set olkCopy = Nothing
    MsgBox "Finished.", vbInformation + vbOKOnly, "Copy Public Folder Contacts"
End Sub

Open in new window

0
arjanpcCommented:
when i execute that script, and i have a contact named test in both folders, the script don´t remove the old test in the target folder
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.