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
 
D

David Sparrius

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.

Thanks in advance..
Submitted using http://www.outlookforums.com

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
SumColumn: Custom DataGrid Column that automatically shows Sum/Count/Average in DataGrid Footer.
http://www.eggheadcafe.com/tutorial...33-1248becf3e16/sumcolumn-custom-datagri.aspx
 
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.
 

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