PC Review


Reply
Thread Tools Rate Thread

Copy Contacts in a Public Folder to a Local Contacts Subfolder

 
 
Phil G
Guest
Posts: n/a
 
      7th Jan 2010
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
 
Reply With Quote
 
 
 
 
Michael Bauer [MVP - Outlook]
Guest
Posts: n/a
 
      8th Jan 2010



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

 
Reply With Quote
 
Phil G
Guest
Posts: n/a
 
      8th Jan 2010
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
 
Reply With Quote
 
Michael Bauer [MVP - Outlook]
Guest
Posts: n/a
 
      10th Jan 2010


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

 
Reply With Quote
 
Phil G
Guest
Posts: n/a
 
      11th Jan 2010
anyone?.
Submitted using http://www.outlookforums.com
 
Reply With Quote
 
Phil G
Guest
Posts: n/a
 
      11th Jan 2010
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
 
Reply With Quote
 
David Sparrius
Guest
Posts: n/a
 
      15th Jan 2010

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/tutorials...m-datagri.aspx
 
Reply With Quote
 
Sue Mosher [MVP]
Guest
Posts: n/a
 
      15th Jan 2010
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, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


<David Sparrius> wrote in message news:(E-Mail Removed)...
> 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.




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy contacts from public folder to outlook contacts list =?Utf-8?B?RGF2aWQgR29sZGJlcmc=?= Microsoft Outlook Contacts 1 25th Sep 2007 01:50 AM
How to share outlook 2003 customize contacts or contacts subfolder without do it on public folder? Sue Mosher [MVP-Outlook] Microsoft Outlook Contacts 2 28th Jun 2007 12:32 PM
Copy from public contacts to local folder Cecco Microsoft Outlook VBA Programming 4 23rd Jun 2006 02:49 PM
Cannot copy contacts from Outlook 2000 mailbox to Public Folder Contacts Ken Hack Microsoft Outlook Contacts 0 15th Sep 2004 04:42 PM
How can I make my address book use my contacts folder and contacts subfolder Annette Wallace Microsoft Outlook Contacts 1 30th Sep 2003 05:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:01 AM.