Article ID: 150002
Article Last Modified on 8/18/2005
Firstname Surname Homephone
--------- ------- ---------
D D 4
B B 2
A A 1
C C 3
'====================================================================
'Macro SortScheduleContacts
'This macro only sorts the firstname, surname, and homephone fields
'and will need to be expanded to cover all additional contact fields
'====================================================================
Sub SortScheduleContacts()
Dim objSched, objTable, objItem As Object
Dim i, j As Integer
'Create the Schedule+ object
Set objSched = CreateObject("scheduleplus.application.7")
'Creates the contacts database object
Set objTable = objSched.ScheduleSelected.Contacts
'Moves to first row of contact list
objTable.Reset
For i = 1 To objTable.Rows
'Get item in contacts database
Set objItem = objTable.Item
'Copy contact details to worksheet
Cells(i, 1).Value = Format(objItem.FirstName)
Cells(i, 2).Value = Format(objItem.lastname)
Cells(i, 3).Value = Format(objItem.phonehome)
'Go to Next item
objTable.skip
Next
'Sorts the contact list on worksheet (sorts on column A)
Range("a1").CurrentRegion.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom
'Deletes all items on schedule contact list
objTable.Reset
For i = 1 To objTable.Rows
Set objItem = objTable.Item
objTable.deleteitem (objItem.itemid)
objTable.skip
Next
'Copies sorted contact list from worksheet to Schedule+ 95
Range("a1").CurrentRegion.Select
j = Selection.Rows.Count
For i = j To 1 Step -1
'Creates a blank new entry in the table
Set objItem = objTable.New
'Creates new entries in the contacts database
objItem.SetProperties FirstName:=Cells(i, 1)
objItem.SetProperties lastname:=Cells(i, 2)
objItem.SetProperties phonehome:=Cells(i, 3)
Next
'Delete objects
Set objItem = Nothing
Set objTable = Nothing
Set objSched = Nothing
End Sub
For more information about programming Schedule+, see the Microsoft
Developer Network compact disc.
Additional query words: XL7 Contact Sort Schedule MSDN CD-ROM
Keywords: KB150002