K
Kelley
I am pretty new to VBA programming, but with some help I have been
able to populate a ComboBox in Excel with Last Names from my Customers
folder in Outlook. Unfortunately, the list does not come in sorted
properly. I have tried to add code to correct this, but it gives an
error at run time. The code that follows is working properly with the
offending code commented out. When I remove the ' from those two
lines, it doesn't work.
Any help would be greatly appreciated. - Kelley New
_____
Option Explicit
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim Fldr As Outlook.MAPIFolder
Dim olCi As Outlook.ContactItem
Dim custFldr As Outlook.MAPIFolder
Private Sub UserForm_Initialize()
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.Folders(1)
Set custFldr = Fldr.Folders("Customers")
'Set olCi = custFldr.Items
'olCi.Sort "[LastName]", False
For Each olCi In custFldr.Items
Me.ComboBox1.AddItem olCi.LastName
Next olCi
End Sub
able to populate a ComboBox in Excel with Last Names from my Customers
folder in Outlook. Unfortunately, the list does not come in sorted
properly. I have tried to add code to correct this, but it gives an
error at run time. The code that follows is working properly with the
offending code commented out. When I remove the ' from those two
lines, it doesn't work.
Any help would be greatly appreciated. - Kelley New
_____
Option Explicit
Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim Fldr As Outlook.MAPIFolder
Dim olCi As Outlook.ContactItem
Dim custFldr As Outlook.MAPIFolder
Private Sub UserForm_Initialize()
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.Folders(1)
Set custFldr = Fldr.Folders("Customers")
'Set olCi = custFldr.Items
'olCi.Sort "[LastName]", False
For Each olCi In custFldr.Items
Me.ComboBox1.AddItem olCi.LastName
Next olCi
End Sub