我成功地能够填充我的Outlook联系人文件夹的内容的2列列表框,并将该信息发送到单击文本框...唉,我如何排序列表框?VBA排序Outlook联系人列表框
Private Sub getOutlookContacts()
Dim i As Integer
Dim oOutlookApp As Outlook.Application
Dim oOutlookNameSpace As Outlook.NameSpace
Dim oContacts As Outlook.MAPIFolder
Dim oContact As Outlook.ContactItem
On Error Resume Next
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
End If
Set oOutlookNameSpace = oOutlookApp.GetNamespace("MAPI")
'Get the contactfolder
Set oContacts = oOutlookNameSpace.GetDefaultFolder(olFolderContacts)
Set oContact = oContacts.Items
'oContacts.Sort "[FullName]", False, olAscending
For Each oContact In oContacts.Items
Me.ListBox1.AddItem oContact.FullName
Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = oContact.BusinessAddress
i = i + 1
Next
Set oContact = Nothing
Set oContacts = Nothing
Set oOutlookNameSpace = Nothing
Set oOutlookApp = Nothing
End Sub
当你得到预期的答案,你应该接受它。 – Pieniadz 2011-09-19 13:20:21