none
Copy GAL Entries to Personal Contacts RRS feed

  • Question

  • I am trying to use VBA to copy GAL entries to the Personal Contacts address list. I can see how to use the AddressEntry to add an entry to the address list, but I don't see how I can put what is essentially the information from the ContactItem into the AddressEntry. There are no named properties to use in an AddressEntry.

    There is a method to get such an object from the AddressEntry (GetContact), but I cannot see any corresponding property or method to use to set this property in the AddressEntry. How can this be done? Obviously this information is available to retrieve. For example, how does one set the email address of an AddressEntry in the Personal Contacts to the value of the email address in an AddressEntry in the GAL? That is just one field, but there are obviously others.


    Mike

    Monday, September 23, 2013 9:58 PM

Answers

  • Folder.Items.Add([type]) will add a new item to the Items collection of a folder. Look at the Items collection object.

    You can use that method to add an item to a specific folder. Using Application.CreateItem() would create the item of the specified type in the default folder for that type of item.

    As Outlook is a COM application bear in mind that Outlook collections (Items, Folders, etc.) all start with an index of 1, not 0.

    As a general rule if you look in the Outlook VBA project (Alt+F11) and use the Object Browser on objects/methods/events/properties, the help will have sample code. It will be in VBA, but that's easy to translate into a .NET language.

    A great reference site for all things related to Outlook programming would be www.outlookcode.com. That has all sorts of samples and information. Not that much in .NET, some, but very useful information.


    Ken Slovak MVP - Outlook

    Thursday, September 26, 2013 2:05 PM
    Moderator

All replies

  • Hi Mike,

    Thank you for posting in the MSDN Forum.

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best regards,

    Fei


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 25, 2013 11:52 AM
    Moderator
  • In this case you're working with GAL entries, so you know the entries are Exchange users. So if you get an AddressEntry from the GAL and use AddressEntry.GetExchangeUser() to get an ExchangeUser object you can use the properties from that object to populate your new contact item.

    For example, you can read AddressEntry.BusinessTelephoneNumber and use that value to set the equivalent property in the contact item.


    Ken Slovak MVP - Outlook

    Wednesday, September 25, 2013 2:39 PM
    Moderator
  • Well, what you say is true, and it is as far as I can get. You very aptly describe how to GET the information. That has not been a problem. I can even put that information into a new instance of a Contact Item. The problem is there is no SET available to put the Contact Item in an AddressEntry. Also, there is no property such as BusinessTelephoneNumber in the AddressEntry class. I can see how to GET the info. It is actually setting the properties in a new instance of an AddressEntry that is problematic for me.

    Mike

    Wednesday, September 25, 2013 6:20 PM
  • Why do you think you need to do anything to set any AddressEntry properties when you create a contact item? I've never done that in over 15 years of programming Outlook.

    Once the new contact is created and saved in a Contacts folder it's part of that AddressList's AddressEntries collection automatically. The AddressEntry can be retrieved from that collection in that AddressList and it will have any properties that were set on the contact item.


    Ken Slovak MVP - Outlook

    Wednesday, September 25, 2013 6:31 PM
    Moderator
  • I will certainly yield to your 15 years experience Ken. I do not regularly do much office automation. Only on an as needed basis. I have a user that wants to sync their smartphone with the GAL, but the sync only works on the personal contacts, so I am trying to automate a copy from the GAL to their personal contacts. My method has generally been to figure it out from the Office reference, but for some reason I am just not getting it because I think I am applying a different paradigm that I should to the situation.

    I did a search and found I could get the global address list and personal address list (contacts) and so that is where I started working to figure it out. I saw references to Folders as I looked through the docs, but did not go down that path.

    So based on your information, I looked into the Folder Class, and while I see an Items method that returns a collection of Items in a folder, there appears to be no ADD method I can find to add an Item to the Items Collection in a Folder. This is not consistent with what is normally done in .NET classes that have collections. So how do I do this. Just add the ContactItem to the collection I get back from the Folder object?

    Sorry I seem so out of it, but I have been able to find answers to things like this in the .NET reference library, but I just don't have the aptitude to do the same in the Outlook reference. So be kind and lead me by the hand a little and don't assume I have 15 years of background to help me.


    Mike

    Wednesday, September 25, 2013 9:01 PM
  • Folder.Items.Add([type]) will add a new item to the Items collection of a folder. Look at the Items collection object.

    You can use that method to add an item to a specific folder. Using Application.CreateItem() would create the item of the specified type in the default folder for that type of item.

    As Outlook is a COM application bear in mind that Outlook collections (Items, Folders, etc.) all start with an index of 1, not 0.

    As a general rule if you look in the Outlook VBA project (Alt+F11) and use the Object Browser on objects/methods/events/properties, the help will have sample code. It will be in VBA, but that's easy to translate into a .NET language.

    A great reference site for all things related to Outlook programming would be www.outlookcode.com. That has all sorts of samples and information. Not that much in .NET, some, but very useful information.


    Ken Slovak MVP - Outlook

    Thursday, September 26, 2013 2:05 PM
    Moderator