Add Method (AddressEntries Collection) Example

This VBScript example uses the Click event of a CommandButton. The name in the "To" field of the form is located in the Global Address List as well as the manager for that person. Both of these entries are added to the sender's Personal Address Book using the Add method.

Sub CommandButton1_Click()
    myName = Item.To
    Set myNameSpace = Application.GetNameSpace("MAPI")
    Set myGAddressList = myNameSpace.AddressLists("Global Address List")
    Set myGEntries = myGAddressList.AddressEntries
    Set myGEntry = myGEntries(myName)
    myManager = myGEntry.Manager    
    Set myGEntry2 = myGEntries(myManager)
    Set myPAddressList = myNameSpace.AddressLists("Personal Address Book")
    Set myPEntries = myPAddressList.AddressEntries
    'Add a new AddressEntry object to the personal 
    'address collection with the name, address, and
    'manager of the name in your To field.
    Set myPEntry = myPEntries.Add("Microsoft Mail Address", myName)
    myPEntry.Address = myGEntry.Address
    myPEntry.Manager = myGentry.Manager
    'Update to persist the collection.
    myPEntry.Update
    'Now add the manager's info. to
    'the Personal address collection.
    Set myPEntry2 = myPEntries.Add("Microsoft Mail Address", myManager)
    myPEntry2.Address = myGEntry2.Address
    myPEntry2.Manager = myGentry2.Manager
    myPEntry2.Update
End Sub