akcramblet
New Member
- Joined
- Jul 12, 2010
- Messages
- 10
I made an excel function that will return employee names stored in MS Outlook by referencing their employee ID numbers. The function works ok, but it's too slow. I'm sort of blathering my way through VBA and could use some ideas to speed things up. Any help is appreciated.
Here is what I came up with:
Function lookupContact(eeNumber As String)
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olCi As ContactItem
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.Folders("Mailbox - Doe, John").Folders("Special Contacts")
For Each olCi In Fldr.Items
If olCi.OrganizationalIDNumber = eeNumber Then
lookupContact = olCi.FileAs
End If
Next olCi
Set olCi = Nothing
Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Function
Here is what I came up with:
Function lookupContact(eeNumber As String)
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olCi As ContactItem
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.Folders("Mailbox - Doe, John").Folders("Special Contacts")
For Each olCi In Fldr.Items
If olCi.OrganizationalIDNumber = eeNumber Then
lookupContact = olCi.FileAs
End If
Next olCi
Set olCi = Nothing
Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Function