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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.olFolderContacts)
>
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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.OlDefaultFolders.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
>
>
>