Copy Contacts in a Public Folder to a Local Contacts Subfolder

Status
Not open for further replies.
P

Phil G

Our company stores a list of company contacts in:

Public Folders->All Public Folders->xxx Corp->yyyy-> Company Contacts

Every start up I would like a macro to copy these contacts to a sub folder of the local contacts called "Company Contacts". (So they sync with our blackberry's). If the program could be smart enough to only update the subfolder that would be great (check for changes and make those, not copy every contact every time), but not necessary.

I don't know visual basic, but I would be willing to look at a couple basic tutorials to figure this out.

Thanks in advance..
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You can learn a lot by using the object browser (f2), switch from <All libraries> to Outlook. There you can get help and code samples for every object and its methods, just select one and press f1. For instance, select ContactItem in the left pane, then its Copy function in the right pane, then press f1.

If the Public Folders are visible in your Outlook, you can access them through the Folders collection of the Namespace object. Instead of looping through all of the contacts in the public folder, you could use the Restrict function of the Items collection, and filter for LastModifiedDate in order to get only those items modified since your last sync. After a sync. you need to store that value anywhere.

In order to access your personal contacts folder, see the GetDefaultFolder function.

Best regards

Michael Bauer
 
P

Phil G

Thanks for the pointers. This is what I came up with:

Private Sub Application_Startup()

Dim myNameSpace As Outlook.namespace

Dim myContactsFolder As Outlook.Folder

Dim myCompanyContactsFolder As Outlook.Folder

Dim myPublicContactsFolder As Outlook.Folder

Set myNameSpace = Application.GetNamespace("MAPI")

Set myContactsFolder = myNameSpace.GetDefaultFolder(olFolderContacts)

Set myCompanyContactsFolder = myFolder.Folders.Add("Company Contacts")

Set myPublicContactsFolder = myNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders ).Folder(xxx yyy xxx yyy).Folder(xxx yyy).Item(xxx yyy Contacts).CopyTo(myCompanyContactsFolder)

End Sub

Unfortunately the last line shoots me an error because of the spaces (and possibly other things) :(

I looked at the restrict method and I understood the logic behind it but I don't think I have the ability to implement it yet..
 
P

Phil G

Ok, fixed a couple things (I think) and now I have:

Private Sub Application_Startup()

Dim myNameSpace As Outlook.namespace

Dim myContactsFolder As Outlook.Folder

Dim myCompanyContactsFolder As Outlook.Folder

Dim myPublicContactsFolder As Outlook.Folder

Set myNameSpace = Application.GetNamespace("MAPI")

Set myContactsFolder = myNameSpace.GetDefaultFolder(olFolderContacts)

Set myCompanyContactsFolder = myContactsFolder.Folders.Add("Company Contacts")

Set myPublicContactsFolder = myNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders ).Folder( "C3 Group Inc. Public Folders").Folder("C3 Group").Item("C3 Group Contacts").CopyTo(myCompanyContactsFolder)

End Sub

Two things, I can't figure out how to check if the folder already exists, and I get an error on my last line..
 
D

David Sparrius

Copy individual contacts

Hi,

We have the same problem. However, I'd like to modify the source code of the public contacts form in the public folder and whenever the user opens up the contact and thus the form opens, a .VBA script kicks in and copies the current contact only to the personal address book. I've purchased a couple of automation tools that had huge problems with duplicates so we dumped them and decided to do it ourselves.

As part of this, I'd like to check to see if the record in the personal address book exists, and if it does, delete it.

As we don?t actually use the data in the personal address book for any purpose other than blackberry, bi-synchronization is pointless.

If anyone has any code that could do this, I?d be very grateful.

Phil G wrote:

Copy Contacts in a Public Folder to a Local Contacts Subfolder

07-Jan-10

Our company stores a list of company contacts in:

Public Folders->All Public Folders->xxx Corp->yyyy-> Company Contacts

Every start up I would like a macro to copy these contacts to a sub folder of the local contacts called "Company Contacts". (So they sync with our blackberry's). If the program could be smart enough to only update the subfolder that would be great (check for changes and make those, not copy every contact every time), but not necessary.

I do not know visual basic, but I would be willing to look at a couple basic tutorials to figure this out.
 
S

Sue Mosher [MVP]

Current versions of Outlook don't use a Personal Address Book by default. Are you instead referring to the user's personal Contacts folder? If so, you can use the Items.Find method to look for a contact by name or email address and, if it exists, delete it. Help has details on how to use that method.

BTW, the code behind an Outlook form is VBScript, not VBA.

Sue Mosher
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
T Macro to find contacts by category and copy them to another folder Outlook VBA and Custom Forms 15
JimR Copy or move contacts into BCM? BCM (Business Contact Manager) 1
Z Copy Outlook 2007 "AutoComplete Contacts” to Outlook 2010 Using Outlook 7
F VBScript copy contacts and remove duplicates Using Outlook 1
R how to copy a list of email contacts and paste them only as names (not names + email address) Using Outlook 12
D Copy Appointment Body to Task Body Outlook VBA and Custom Forms 0
M copy field value to custom field Outlook VBA and Custom Forms 0
O In Agenda-view - How to copy an existing item months ahead or back? Using Outlook 0
C Move or copy from field to field Outlook VBA and Custom Forms 0
Z Copy specific email body text Outlook VBA and Custom Forms 0
B Need to Copy an email to a subfolder Outlook VBA and Custom Forms 2
O Outlook 365 - How to create / copy a new contact from an existing one? Using Outlook 5
S Copy Tasks/Reminders from Shared Mailbox to Personal Tasks/Reminders Outlook VBA and Custom Forms 0
A Cannot copy this folder because it may contain private items Using Outlook 0
C Copy Move item won't work Outlook VBA and Custom Forms 2
Z VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
Commodore Move turns into "copy" Using Outlook 3
C Copy Outlook contact field value to another field Outlook VBA and Custom Forms 1
J Copy to calendar function no longer working in outlook 365 Using Outlook 5
F Copy and replace not update contact in another pst Using Outlook 0
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
N Outlook rules don't create a copy for bcc'ed emails Using Outlook 3
geofferyh Outlook 2010 How to Copy Outlook Attachment to a Specific Folder? Outlook VBA and Custom Forms 3
S Custom Form, copy user field data to message body Outlook VBA and Custom Forms 12
R Copy Outlook Public Folders to a File Server Shared Folder Using Outlook 0
K Outlook Rules: Move a Copy Using Outlook 4
oliv- HOW TO COPY /USE FOLDERS ICONS Outlook VBA and Custom Forms 2
E Copy e-mail body from outlook and insert into excel Outlook VBA and Custom Forms 3
B Copy/Move Exchange inbox to Pop inbox Using Outlook 4
R Sending email copy (*.msg file) of sent email if subject line contains specific string. Outlook VBA and Custom Forms 1
O Copy mails from many subfolders to 1 foldr Using Outlook 2
K ind specific Subject line from outlook and copy the content of the email body to exce Outlook VBA and Custom Forms 0
K How to find specific header and copy the mail body Using Outlook 0
J Copy or Export Outlook Mail to Excel Outlook VBA and Custom Forms 6
G Copy Contact field to Appointment Custom Form Field Outlook VBA and Custom Forms 2
G How to Copy Multi Select Listbox Data to Appointment Outlook VBA and Custom Forms 3
Carrie Dickey Outlook 2016 created two calendars titled Calendar1 - appear to be a copy Using Outlook 2
P How to copy and append data from Outlook 2016 message into Excel 2016 workbook Using Outlook 0
Stilgar Relsik Create a rule to copy text from an email and paste it in the subject line. Using Outlook 1
R Macro to copy email to excel - Runtime Error 91 Object Variable Not Set Outlook VBA and Custom Forms 11
H Macro to Copy Specific content from Mail Body and Paste to Excel Outlook VBA and Custom Forms 4
M How to keep reccurence during copy tasks to calendar? Using Outlook 1
Diane Poremsky Copy New Appointments to Another Calendar using VBA Using Outlook 0
Diane Poremsky Use a macro to copy data in Outlook email to Excel workbook Using Outlook 0
C Copy Task to Non-Microsoft PIM "Rainlendar" Using Outlook 0
G VBA Copy draft email to a new email - attachments not copided Using Outlook 7
C Copy email to excel runtime error 5020 Using Outlook 5
I Copy email from folder to folder - FAILS Using Outlook 5
M Copy new appointments created in multiple shared calendars to another exchange calendar Outlook VBA and Custom Forms 1

Similar threads

Top