473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Accessing outlook contacts

Hi

I am trying to access outlook contacts folders and delete the contacts that
do not contain a certain category value in the categories field. I have
written the below code but am stuck with the error on the indicated line.
Any help would be appreciated.

Thanks

Regards
Dim O As Outlook.Application
Dim F As Outlook.MAPIFolder
Dim ICount As Long
Dim oContact As Outlook.ContactItem
Dim obj As Outlook.ContactItem

O = New Outlook.Application
F = O.Session.GetDefaultFolder(Outlook.OlDefaultFolder s.olFolderContacts)
For Each obj In F.Items() ' This line gives error: Expression is of type
'Outlook.Items', which is not a collection type.
If TypeOf obj Is Outlook.ContactItem Then
oContact = obj
If InStr(oContact.Categories, "mycat") Then
oContact.Delete()
End If
End If
Next
Nov 21 '05 #1
3 6015
Hi,

Here is a sample console app.

Imports System.Reflection

Imports Outlook = Microsoft.Office.Interop.Outlook

Module Module1

Sub Main()

' Create Outlook application.

Dim oApp As Outlook.Application = New Outlook.Application

' Get Mapi NameSpace.

Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")

oNS.Logon("YourProfileName", Missing.Value, False, True) ' TODO:

' Get Messages collection of Inbox.

Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderContacts)

Dim oItems As Outlook.Items = oInbox.Items

Console.WriteLine("Total : " & oItems.Count)

Console.WriteLine("Total Unread : " & oItems.Count)

' Loop each unread message.

Dim oContact As Outlook.ContactItem

Dim i As Integer

For i = 1 To oItems.Count

Try

oContact = DirectCast(oItems.Item(i), Outlook.ContactItem)

Console.WriteLine(i)

Console.WriteLine(oContact.FullName)

Catch

End Try

Console.WriteLine("---------------------------")

Next

' Log off.

oNS.Logoff()

' Clean up.

oApp = Nothing

oNS = Nothing

oItems = Nothing

oContact = Nothing

End Sub

End Module

Ken

-------------------

"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi

I am trying to access outlook contacts folders and delete the contacts that
do not contain a certain category value in the categories field. I have
written the below code but am stuck with the error on the indicated line.
Any help would be appreciated.

Thanks

Regards
Dim O As Outlook.Application
Dim F As Outlook.MAPIFolder
Dim ICount As Long
Dim oContact As Outlook.ContactItem
Dim obj As Outlook.ContactItem

O = New Outlook.Application
F = O.Session.GetDefaultFolder(Outlook.OlDefaultFolder s.olFolderContacts)
For Each obj In F.Items() ' This line gives error: Expression is of type
'Outlook.Items', which is not a collection type.
If TypeOf obj Is Outlook.ContactItem Then
oContact = obj
If InStr(oContact.Categories, "mycat") Then
oContact.Delete()
End If
End If
Next

Nov 21 '05 #2
Hi

I am getting a "Namespace or type 'Outlook' for the Imports
'Microsoft.Office.Interop.Outlook' cannot be found." error on line Imports
Outlook = Microsoft.Office.Interop.Outlook. Any idea what I am doing wrong?

Thanks

Regards
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
Hi,

Here is a sample console app.

Imports System.Reflection

Imports Outlook = Microsoft.Office.Interop.Outlook

Module Module1

Sub Main()

' Create Outlook application.

Dim oApp As Outlook.Application = New Outlook.Application

' Get Mapi NameSpace.

Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")

oNS.Logon("YourProfileName", Missing.Value, False, True) ' TODO:

' Get Messages collection of Inbox.

Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderContacts)

Dim oItems As Outlook.Items = oInbox.Items

Console.WriteLine("Total : " & oItems.Count)

Console.WriteLine("Total Unread : " & oItems.Count)

' Loop each unread message.

Dim oContact As Outlook.ContactItem

Dim i As Integer

For i = 1 To oItems.Count

Try

oContact = DirectCast(oItems.Item(i), Outlook.ContactItem)

Console.WriteLine(i)

Console.WriteLine(oContact.FullName)

Catch

End Try

Console.WriteLine("---------------------------")

Next

' Log off.

oNS.Logoff()

' Clean up.

oApp = Nothing

oNS = Nothing

oItems = Nothing

oContact = Nothing

End Sub

End Module

Ken

-------------------

"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi

I am trying to access outlook contacts folders and delete the contacts that do not contain a certain category value in the categories field. I have
written the below code but am stuck with the error on the indicated line.
Any help would be appreciated.

Thanks

Regards
Dim O As Outlook.Application
Dim F As Outlook.MAPIFolder
Dim ICount As Long
Dim oContact As Outlook.ContactItem
Dim obj As Outlook.ContactItem

O = New Outlook.Application
F = O.Session.GetDefaultFolder(Outlook.OlDefaultFolder s.olFolderContacts) For Each obj In F.Items() ' This line gives error: Expression is of type
'Outlook.Items', which is not a collection type.
If TypeOf obj Is Outlook.ContactItem Then
oContact = obj
If InStr(oContact.Categories, "mycat") Then
oContact.Delete()
End If
End If
Next

Nov 21 '05 #3
Hi,

I would recomend using the office interop assemblies they solve some
problems with working with office. If you are not using them you can get
rid of that imports statement.

http://msdn.microsoft.com/library/de...embliesFAQ.asp

Ken
--------------------------------
"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
Hi

I am getting a "Namespace or type 'Outlook' for the Imports
'Microsoft.Office.Interop.Outlook' cannot be found." error on line Imports
Outlook = Microsoft.Office.Interop.Outlook. Any idea what I am doing wrong?

Thanks

Regards
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
Hi,

Here is a sample console app.

Imports System.Reflection

Imports Outlook = Microsoft.Office.Interop.Outlook

Module Module1

Sub Main()

' Create Outlook application.

Dim oApp As Outlook.Application = New Outlook.Application

' Get Mapi NameSpace.

Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")

oNS.Logon("YourProfileName", Missing.Value, False, True) ' TODO:

' Get Messages collection of Inbox.

Dim oInbox As Outlook.MAPIFolder =
oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderContacts)

Dim oItems As Outlook.Items = oInbox.Items

Console.WriteLine("Total : " & oItems.Count)

Console.WriteLine("Total Unread : " & oItems.Count)

' Loop each unread message.

Dim oContact As Outlook.ContactItem

Dim i As Integer

For i = 1 To oItems.Count

Try

oContact = DirectCast(oItems.Item(i), Outlook.ContactItem)

Console.WriteLine(i)

Console.WriteLine(oContact.FullName)

Catch

End Try

Console.WriteLine("---------------------------")

Next

' Log off.

oNS.Logoff()

' Clean up.

oApp = Nothing

oNS = Nothing

oItems = Nothing

oContact = Nothing

End Sub

End Module

Ken

-------------------

"John" <Jo**@nospam.infovis.co.uk> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi

I am trying to access outlook contacts folders and delete the contacts that do not contain a certain category value in the categories field. I have
written the below code but am stuck with the error on the indicated line.
Any help would be appreciated.

Thanks

Regards
Dim O As Outlook.Application
Dim F As Outlook.MAPIFolder
Dim ICount As Long
Dim oContact As Outlook.ContactItem
Dim obj As Outlook.ContactItem

O = New Outlook.Application
F = O.Session.GetDefaultFolder(Outlook.OlDefaultFolder s.olFolderContacts) For Each obj In F.Items() ' This line gives error: Expression is of type
'Outlook.Items', which is not a collection type.
If TypeOf obj Is Outlook.ContactItem Then
oContact = obj
If InStr(oContact.Categories, "mycat") Then
oContact.Delete()
End If
End If
Next


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fritz Switzer | last post by:
Can anyone provide a small snippet in C# that pulls out the Contacts in Outlook XP. I've seen a couple of examples in C++ and VB in previous newsgroup posts, but either the originals didn't work...
2
by: Kurt Häusler | last post by:
Hi. I have am using c# and the outlook object model to access the outlook address book, but once you have more than a 100 or so contacts in the folder it takes far too long to iterate through...
4
by: lauren quantrell | last post by:
Is there a way to open the MS Outlook address book using VBA and then be able to do something with the return value? I want users to click an icon to open the Outlook address book then when an...
2
by: Adhiraj | last post by:
Hi, I want to know if one can access Outlook Express through C#. I want to access the contacts. I found many links for Microsoft Outlook, but not a single link for Outlook Express. Thnks in...
1
by: SWu | last post by:
Hello everyone, I am working on an Internet website for an Application Service Provider. A user can store employee details on the site. I am now researching the feasibility of accessing the...
0
by: Bob | last post by:
Hi, I'm new to Python and I want to create a script that will import contactitems into an Outlook Public Folder. Therefore I've installed the Python for Windows Extensions. This way I can...
1
by: charliej2001 | last post by:
Hi all My access database has import/export capabiltiy of contact details between outlook. The database is getting big now (1000+ contacts) and so are the outlook address books that have the...
0
by: mrabie | last post by:
Hi All, I am trying to write an application to access the contacts database that comes with Windows Vista and also the Outlook (2007) contacts database, can you please point me to where i can...
6
by: Kevin | last post by:
In my business, I use Quickbooks extensively for billing and accounting and a custom built Access DB for project management. I recently began using MS Outlooks contacts quite extensively as well...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.