![]() |
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
|
|||
|
|||
![]()
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 |
#2
|
|||
|
|||
![]() #1 This function returns a collection: Funtion Sample1() as Outlook.Items ... Set Sample1 = objFolder.Items End It's called like this: Dim Result as Outlook.Items Set Result=Sample1 #2 This uses the argument passed to the sub to return the result: Sub Sample2(Collection as Outlook.Items) .. Set Collection = objFolder.Items End Sub It's called like this: Dim Result as Outlook.Items Sample2 Result #3 This uses a variable on the module level to make the data available to others: Private m_Result as Outlook.Items Sub Sample3() ... Set m_Result = objFolder.Items End Sub -- Best regards Michael Bauer - MVP Outlook Use Outlook Categories? This is Your Tool: http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6 Am Sun, 10 Feb 2008 20:08:02 -0800 schrieb 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? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Import function limiting contacts | Nikki | Outlook - Using Contacts | 1 | October 1st 07 07:05 AM |
Problem in view Outlook 2003 contacts. Error " The properties dialog box could not be displayed. An invalid ENTRYID was pass" | Jaweed Patel | Outlook - Using Contacts | 0 | April 17th 07 11:31 AM |
Search function in contacts doesn't work | Cowtoon | Outlook - Using Contacts | 1 | February 17th 07 09:35 PM |
outlook contacts collection | Dick | Outlook and VBA | 1 | January 3rd 07 02:40 PM |
Any function to print a Contacts page? | fly2moon2 | Outlook - Using Contacts | 1 | September 24th 06 04:09 PM |