![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi,
I have the following code that gets my contacts from outlook and lists them in a listbox on a form to select one. My problem is i have about 1000 contacts and it takes a while to load them into a userform in Excel 2003,then when i selected the contact and close the userform it then takes the same time to unload. Can anyone advise me on any changes i can make in the code to speed it up! Many thanks in advance Regards Adam Private Sub UserForm_Initialize() Dim olApp As Outlook.Application Dim oContact As Outlook.ContactItem Dim oContactFolder As Outlook.MAPIFolder Dim oContactItems As Outlook.Items Dim oNS As Outlook.Namespace Dim i As Long Dim j As Long Dim arr() With Me.ComboBox1 .ColumnCount = 3 .ColumnWidths = "175 pt;150 pt;200 pt" .TextColumn = -1 End With On Error GoTo XIT Set olApp = New Outlook.Application Set oNS = olApp.GetNamespace("MAPI") Set oContactFolder = oNS.GetDefaultFolder(olFolderContacts) Set oContactItems = oContactFolder.Items With Me For i = 1 To oContactItems.Count If oContactItems.Item(i).Class = olContact Then Set oContact = oContactItems.Item(i) If oContact.Categories = "Customer " Then j = j + 1 ReDim Preserve arr(0 To 2, 1 To j) With oContact arr(0, j) = .CompanyName arr(1, j) = .FullName arr(2, j) = .BusinessAddress End With End If End If Next i Me.ComboBox1.List() = Application.Transpose(arr) End With XIT: Set oContact = Nothing Set oContactItems = Nothing Set oContactFolder = Nothing Set oNS = Nothing Set olApp = Nothing End Sub |
Ads |
#2
|
|||
|
|||
![]()
Instead of looping, use the Items.Restrict method with a filter on the
Categories property for "Customer". That should at least trim your collection. Otherwise, if you recode using CDO 1.21 you'll get faster looping through the collection - whether it's fast enough to be worth the effort for 1000 contacts is probably debatable! -- Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.) Try Picture Attachments Wizard for Outlook: http://www.collaborativeinnovations.ca Blog: http://blogs.officezealot.com/legault/ "Adam" wrote: Hi, I have the following code that gets my contacts from outlook and lists them in a listbox on a form to select one. My problem is i have about 1000 contacts and it takes a while to load them into a userform in Excel 2003,then when i selected the contact and close the userform it then takes the same time to unload. Can anyone advise me on any changes i can make in the code to speed it up! Many thanks in advance Regards Adam Private Sub UserForm_Initialize() Dim olApp As Outlook.Application Dim oContact As Outlook.ContactItem Dim oContactFolder As Outlook.MAPIFolder Dim oContactItems As Outlook.Items Dim oNS As Outlook.Namespace Dim i As Long Dim j As Long Dim arr() With Me.ComboBox1 .ColumnCount = 3 .ColumnWidths = "175 pt;150 pt;200 pt" .TextColumn = -1 End With On Error GoTo XIT Set olApp = New Outlook.Application Set oNS = olApp.GetNamespace("MAPI") Set oContactFolder = oNS.GetDefaultFolder(olFolderContacts) Set oContactItems = oContactFolder.Items With Me For i = 1 To oContactItems.Count If oContactItems.Item(i).Class = olContact Then Set oContact = oContactItems.Item(i) If oContact.Categories = "Customer " Then j = j + 1 ReDim Preserve arr(0 To 2, 1 To j) With oContact arr(0, j) = .CompanyName arr(1, j) = .FullName arr(2, j) = .BusinessAddress End With End If End If Next i Me.ComboBox1.List() = Application.Transpose(arr) End With XIT: Set oContact = Nothing Set oContactItems = Nothing Set oContactFolder = Nothing Set oNS = Nothing Set olApp = Nothing End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Synch excel list with contacts distribution list | Resi | Outlook - Using Contacts | 8 | March 15th 10 09:33 PM |
How do I export an Excel list to a contacts distribution list | HayesV | Outlook - Using Contacts | 3 | December 15th 08 06:00 PM |
Outlook contacts list into Excel worksheet? | Ed | Outlook and VBA | 3 | February 1st 07 11:33 PM |
HELP HELP - Importing Contacts from Excel List | TotallyConfused | Outlook - Using Contacts | 9 | February 20th 06 07:10 PM |
Pls Help!! New Contacts from Excel List | TotallyConfused | Outlook - Using Contacts | 3 | February 15th 06 09:31 AM |