' Excel Visual Basic Macro demonstrating
' use of the AddressBook api
Sub TestAddressBook()

' This declaration instantiates the Application object
' The CApplication refers to the coclass
' note that by declaring these as specific types
' (rather than "object"), VB is able to use the
' static binding to the interface methods
Dim app As New CApplication
' This variable will hold an address book reference
Dim addressbook As addressbook
' This will hold an Address reference
Dim entry As Address

' Range is an Excel object refering to a range of cells
Dim loc As Range
Dim Row As Integer

Set loc = Range("A1")
' open the AddressBook created in the Perl script testCreate.pl
Set addressbook = app.AddressBooks.Open("g:\AddressBook\MyBook")
Row = 0
' This implicitly uses the IEnumVARIANT interface
For Each entry In addressbook
    ' put the name in the first column
    loc.Offset(Row, 0).Value = entry.Name
    ' put the phone number in the second column
    loc.Offset(Row, 1).Value = entry.Phone
    Row = Row + 1
Next
End Sub

