View Single Post
  #1  
Old February 11th 08, 05:08 AM posted to microsoft.public.outlook.program_vba
Southern at Heart
external usenet poster
 
Posts: 34
Default how to pass a collection of contacts from a function

Dim ol As Object
Dim olns As Object
Dim objFolder As Object
Dim objAllContacts As Object
Dim Contact As Object
Dim counter As Integer
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set objFolder = olns.PickFolder
If objFolder Is Nothing Then
Exit Sub
ElseIf objFolder.DefaultItemType olContactItem Then
Exit Sub
End If
Set objAllContacts = objFolder.Items

I have several subs that all start out with this code above to get a
collection of contacts
Can I make this a function that returns objAllContacts somehow? I've tried
something like this code below, but can't get it to work...

sub test()
Dim MyContacts as Object
MyContacts = GetContacts
....
End Sub


....I then made a function like this:

Function GetContacts()
Dim ol As Object
Dim olns As Object
Dim objFolder As Object
Dim objAllContacts As Object
Dim Contact As Object
Dim counter As Integer
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set objFolder = olns.PickFolder
If objFolder Is Nothing Then
Exit Sub
ElseIf objFolder.DefaultItemType olContactItem Then
Exit Sub
End If
Set objAllContacts = objFolder.Items
GetContacts=objAllContacts
End Function

....but it doesn't work?
Ads