S
Southern at Heart
The following code gets a list of all the different Company names used in my
Outlook folder. (maybe there's a better way of doing this...)
Now I have the string CompanyList set to a few dozen names, with a delimiter
of vbCrLf. How do I load this into my combobox on my userform, for the user
to select one? (Do I want a combobox or a listbox--I'd like the user to be
able to choose several, actually)
thanks,
Southern@Heart
Public CompanyList As String
Sub Outlook_Company()
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items
iNumContacts = objItems.Count
System.Cursor = wdCursorWait
If iNumContacts <> 0 Then
For I = 1 To iNumContacts
If TypeName(objItems(I)) = "ContactItem" Then
Set c = objItems(I)
If c.CompanyName <> "" Then AddCompany (c.CompanyName)
'strCompany = c.CompanyName
End If
Next I
End If
System.Cursor = wdCursorNormal
MsgBox CompanyList
End Sub
Sub AddCompany(strCompany As String)
If CompanyList = "" Then
CompanyList = strCompany
Exit Sub
End If
If Not InStr(1, CompanyList, strCompany) Then
CompanyList = CompanyList & vbCrLf & strCompany
End If
End Sub
Outlook folder. (maybe there's a better way of doing this...)
Now I have the string CompanyList set to a few dozen names, with a delimiter
of vbCrLf. How do I load this into my combobox on my userform, for the user
to select one? (Do I want a combobox or a listbox--I'd like the user to be
able to choose several, actually)
thanks,
Southern@Heart
Public CompanyList As String
Sub Outlook_Company()
Dim ol As New Outlook.Application
Dim olns As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Set olns = ol.GetNamespace("MAPI")
Set cf = olns.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items
iNumContacts = objItems.Count
System.Cursor = wdCursorWait
If iNumContacts <> 0 Then
For I = 1 To iNumContacts
If TypeName(objItems(I)) = "ContactItem" Then
Set c = objItems(I)
If c.CompanyName <> "" Then AddCompany (c.CompanyName)
'strCompany = c.CompanyName
End If
Next I
End If
System.Cursor = wdCursorNormal
MsgBox CompanyList
End Sub
Sub AddCompany(strCompany As String)
If CompanyList = "" Then
CompanyList = strCompany
Exit Sub
End If
If Not InStr(1, CompanyList, strCompany) Then
CompanyList = CompanyList & vbCrLf & strCompany
End If
End Sub