How to Copy Global Addressbook entry to Personal Addressbook through vb program

How to Copy Global Addressbook entry to Personal Addressbook through vb program

Post by lucky_bo » Fri, 07 Dec 2001 17:18:48



How to Copy Global Addressbook entry to Personal Addressbook through vb
program
 
 
 

How to Copy Global Addressbook entry to Personal Addressbook through vb program

Post by Bj?rn Holmgre » Fri, 07 Dec 2001 21:07:42


Try this:

Create a form with two comboboxes (cbSource and cbDest), two listboxes
(lbSource and lbDest) and a commandbutton (cmdCopy). Place the cbSource
combobox above the lbSource listbox and the cbDest combobox above the lbDest
listbox. Then paste the following code into the form's code section. Go to
"Project | References" and select the "Microsoft Outlook x.0 Object
Library". Run the program. Select the source address list in the cbSource
combobox and the destination address list in the cbDest combobox. The
available addresses should be listed in the two listboxes. Select the entry
you want to copy in the lbSource listbox and click the copy commandbutton.
The address should now be copied to the destination address list.
______________________________________________________________________

Private Sub cbDest_Click()
    Dim OA As Outlook.Application
    Dim AL As Outlook.AddressList
    Dim AE As Outlook.AddressEntry
    Me.MousePointer = vbHourglass
    lbDest.Clear
    DoEvents
    Set OA = New Outlook.Application
    For Each AL In OA.Session.AddressLists
        If AL.Name = cbDest.Text Then
            For Each AE In AL.AddressEntries
                lbDest.AddItem AE.Name
            Next
        End If
    Next
    Set OA = Nothing
    Me.MousePointer = vbDefault
End Sub

Private Sub cbSource_Click()
    Dim OA As Outlook.Application
    Dim AL As Outlook.AddressList
    Dim AE As Outlook.AddressEntry
    Me.MousePointer = vbHourglass
    lbSource.Clear
    DoEvents
    Set OA = New Outlook.Application
    For Each AL In OA.Session.AddressLists
        If AL.Name = cbSource.Text Then
            For Each AE In AL.AddressEntries
                lbSource.AddItem AE.Name
            Next
        End If
    Next
    Set OA = Nothing
    Me.MousePointer = vbDefault
End Sub

Private Sub cmdCopy_Click()
    Dim OA As Outlook.Application
    Dim AL As Outlook.AddressList
    Dim ALSource As Outlook.AddressList
    Dim ALDest As Outlook.AddressList
    Dim AE As Outlook.AddressEntry
    Me.MousePointer = vbHourglass
    DoEvents
    Set OA = New Outlook.Application
    For Each AL In OA.Session.AddressLists
        If AL.Name = cbSource.Text Then
            Set ALSource = AL
        End If
    Next
    For Each AL In OA.Session.AddressLists
        If AL.Name = cbDest.Text Then
            Set ALDest = AL
        End If
    Next
    For Each AE In ALSource.AddressEntries
        If AE.Name = lbSource.List(lbSource.ListIndex) Then
            ALDest.AddressEntries.Add AE.Type, AE.Name, AE.Address
        End If
    Next
    Set ALSource = Nothing
    Set ALDest = Nothing
    Set OA = Nothing
    cbDest_Click
    Me.MousePointer = vbDefault
End Sub

Private Sub Form_Load()
    Dim OA As Outlook.Application
    Dim AL As Outlook.AddressList
    Set OA = New Outlook.Application
    For Each AL In OA.Session.AddressLists
        cbSource.AddItem AL.Name
        cbDest.AddItem AL.Name
    Next
    Set OA = Nothing
End Sub
______________________________________________________________________
--
............................................
Bj?rn Holmgren
Concept Development
Guide Integration AB
Olof Asklunds gata 10
SE-421 30 V?stra Fr?lunda, Sweden
Office +46 31 709 50 00
Mobile +46 706 84 01 29
Fax +46 31 709 50 99

............................................


Quote:> How to Copy Global Addressbook entry to Personal Addressbook through vb
> program