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
Stop
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 = "mytest@gmail.com" Then
If MyEMail.Attachments.Count > 0 Then
MyDest = GetFolder("\\Outlook (Gary)\mytest\Attachments")
MyEMail.Move(MyDest)
Else
MyDest = GetFolder("\\Outlook (Gary)\mytest")
MyEMail.Move(MyDest)
End If
End If
Next
End Sub
However, I am getting the error ...
Quote
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 ?

New Topic/Question
Reply



MultiQuote



|