Copy Contacts in a Public Folder to a Local Contacts Subfolder

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..
Submitted using http://www.outlookforums.com
 
M

Michael Bauer [MVP - Outlook]

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 - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 07 Jan 2010 16:03:21 -0500 schrieb 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.
 
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..
Submitted using http://www.outlookforums.com
 
M

Michael Bauer [MVP - Outlook]

1) It's not because of the spaces, but names must be in quotation marks.
ALso, it's a good idea to set a variable to each folder, and break the one
line of code into many lines. That way you can easily see if one folder
doesn't exist. For instance,

set myContactsFolder=
myNameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders )
set myContactsFolder=myContactsFolder.Folder("xxx yyy xxx yyy")
set myContactsFolder=myContactsFolder.Folder("xxx yyy")

2) The folder property for items is called Items, not Item.

3) For a folder the copy function is called CopyTo. For an item it is just
Copy. So, if you want to copy a folder, it would be something like:

Set Folder = myContactsFolder.CopyTo(...)

and if you want to copy an item:

Set Item=myContactsFolder.Items("xyz").Copy

--
Best regards
Michael Bauer - MVP Outlook
Manage and share your categories:
<http://www.vboffice.net/product.html?pub=6&lang=en>


Am Fri, 08 Jan 2010 15:24:55 -0500 schrieb 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..
Submitted using http://www.outlookforums.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top