S
Southern at Heart
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?
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?