• Subject: looping through inbox messages / debugger under Outlook VBA
  • Author: Mark VII
  • Date: 09 Apr
  • References:
Greetings -- I'm trying to automate the process of detecting certain incoming emails and writing them out as plain text files under Outlook 2003. Am running into a couple of problems. I have a rule pointing to a VBA subroutine, and the rule appears to trigger when I use Run Rules Now. However, the VBA IDE does not behave as I am used to in Access, Excel and Project. If I set a breakpoint, the code does not break. Stop statements don't work either. Sometime a MsgBox statement will pop a message box, sometimes not. Debug.Print statements sometime put something in the Immediate window, something not. Not being able to set breakpoints, view the content of variables, watch the loops loop, etc. is making this very hard. The underlying task is to read through the messages in the inbox and write the body of ones that contain a certain keyword out as plain text files. Between what I've found on the net and my own knowledge of object models, here's what I've got at this point. Public Sub ReadMessageBody(oItem As Outlook.MailItem) Dim strId As String Dim oNameSpace As Outlook.NameSpace Dim oInboxItem As Outlook.MailItem Dim oMailItem As Outlook.MailItem Dim oFolder As Outlook.MAPIFolder Dim oMsg As Object Dim strBody As String '* point to the name space Set oNameSpace = Application.GetNamespace("MAPI") '* set a reference to the inbox folder Set oFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox) '* loop through the inbox For Each oInboxItem In oFolder.Items strId = oInboxItem.EntryID Set oMailItem = oNameSpace.GetItemFromID(strId) If Left(oMailItem.Subject, 6) = "Deploy" Then '* save message body as text Else '* something else, ignore End If Next oInboxItem End Sub As best I can determine with no debugging capability is that the sub is called, but does not enter the For...Next loop. Also, it appears to fire once per file in the Inbox. Can anyone give me any suggestions on how the use the IDE in Outlook? This would be a lot easier to get working if I could used the debugger in the usual fashion. Thanks a million...
09 Aprlooping through inbox messages / debugger under Outlook VBA.Mark VII
09 Apr|- Re: looping through inbox messages / debugger under Outlook VBA.Ken Slovak - [MVP - O...
09 Apr|  \ Re: looping through inbox messages / debugger under Outlook VBA.Mark VII
10 Apr|     \ Re: looping through inbox messages / debugger under Outlook VBA.Ken Slovak - [MVP - O...
09 Apr\ Re: looping through inbox messages / debugger under Outlook VBA.Sue Mosher [MVP-Outlook]
10 Apr   \ Re: looping through inbox messages / debugger under Outlook VBA.Mark VII
10 Apr      \ Re: looping through inbox messages / debugger under Outlook VBA.Sue Mosher [MVP-Outlook]
10 Apr         \ Re: looping through inbox messages / debugger under Outlook VBA.Mark VII
All times are in (US) Eastern Daylight Time (GMT -4:00)