1 Replies - 1229 Views - Last Post: 04 October 2012 - 01:12 PM Rate Topic: -----

#1 vodkasoda   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-October 12

Outlook program to sort E:Mails

Posted 03 October 2012 - 08:42 AM

Hi all, I have in the past used a VBA program to sort my E:Mails into Folders.

I now want to write a bit more complex logic, but not in VBA, in VS2010 but am new to it and could do with some advice.

When I create a new Project for Outlook 2007 it automatically generates the following code ...

Public Class ThisAddIn

    Private Sub ThisAddIn_Startup() Handles Me.Startup

    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

End Class

I am assuming that I only need to put any code into here if I specifically want some logic executed at startup & closing of Outlook ?!? Please tell me if I am wrong, I am not a VB expert in any way shape or form, I am a Mainframe programmer so have to fight hard to get my head around the totally different concepts involved !!!

So, my code (which is in the above Class, immediately after the "End Sub" of the "Shutdown" code, is that correct ?) is as follows ...

Private Sub Application_NewMailEx(EntryIDCollection As String) Handles Application.NewMailEx

        Dim MyApp As Outlook.Application
        Dim MyNameSpace As Outlook.NameSpace
        Dim MyFolders As Object
        Dim MyInbox As Outlook.Folder
        Dim MyReadCollection As Microsoft.Office.Interop.Outlook.Items
        Dim MyEMail As Outlook.MailItem

        'Dim MyEMails As Integer
        Dim MyCount As Integer
        Dim MyString As String
        Dim MyMail As Object
        Dim MyAtmt As Outlook.Attachment
        MyApp = New Outlook.Application
        MyNameSpace = MyApp.GetNamespace("MAPI")
        MyFolders = MyNameSpace.Folders
        MyInbox = MyNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

        For Each MyMail In MyInbox
            If MyMail.SenderEmailAddress = "[email protected]" Then
                If MyEMail.Attachments.Count > 0 Then
                    MyDest = GetFolder("\\Outlook (Gary)\mytest\Attachments")
                    MyDest = GetFolder("\\Outlook (Gary)\mytest")
                End If
            End If

    End Sub

However, I am getting the error ...


Expression is of type 'Microsoft.Office.Interop.Outlook.Folder', which is not a collection type.

... on "MyInbox" of the "For Each" line ...

Can anybody help ?

Is This A Good Question/Topic? 0
  • +

Replies To: Outlook program to sort E:Mails

#2 vodkasoda   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-October 12

Re: Outlook program to sort E:Mails

Posted 04 October 2012 - 01:12 PM

This can be closed, I have used a different method ...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1