locked
Runtime error in VBA for Outlook RRS feed

  • Question

  • So I am trying to write a module in Outlook that will parse the emails out of the emails I am being sent in the body of the message. I am getting a 'Runtime 424 Error" at this line of code

        For Each outlookMessage In outlookFolder.Items

    It says that an object is required, I'm pretty sure the error is in reference to For Each outlookMessage In outlookFolder.Items

    Can someone please help me out, I am not very good with VBA and I need some help.

    Here is a portion of the code that I am talking about:

    ' Get all top level folders and find our target email folder.... For iCtr = 1 To OutlookNameSpace.Folders.Item(1).Folders.Count ' handle case sensitivity as I can't type worth a crap If LCase(OutlookNameSpace.Folders.Item(1).Folders(iCtr).Name) = LCase(strTargetFolder) Then 'found our target :) Set outlookFolder = OutlookNameSpace.Folders.Item(1).Folders(iCtr) Exit For ' found it so lets move on End If Next 'set up a header for the data dump, this is for CSV strEmailContents = "User,Remote,Forwarder,Encoding,timestamp" & vbCrLf 'likely should have some error handling here, in case we have found no target folder 'Set myFolderItem = outlookFolder.Items ' I have commenteted out some items to illustrate the call to Sue'strEmailContents Function

    If Not outlookFolder Is Nothing Then For Each outlookMessage In outlookFolder.Items strMsgBody = outlookMessage.Body ' assign message body to a Var ' then use Sue Moshers code to look for stuff in the body ' all of the following stuff in the quotes "" is specific to your needs strEmailContents = strEmailContents & ParseTextLinePair(strMsgBody, "E-mail:") ' strEmailContents = strEmailContents & "," & ParseTextLinePair(strMsgBody, "REMOTE_ADDR=") ' strEmailContents = strEmailContents & "," & ParseTextLinePair(strMsgBody, "HTTP_USER_AGENT=") ' strEmailContents = strEmailContents & "," & ParseTextLinePair(strMsgBody, "HTTP_VIA=") ' strEmailContents = strEmailContents & "," & ParseTextLinePair(strMsgBody, "HTTP_X_FORWARDED_FOR=") ' strEmailContents = strEmailContents & "," & ParseTextLinePair(strMsgBody, "ENCODING=") 'add the email message time stamp, just cause i want it strEmailContents = strEmailContents & "," & outlookMessage.ReceivedTime & vbCrLf 'debug message comment it out for production 'wscript.echo strEmailContents Next

    End If

    Thank you in advanced!

    Thursday, March 13, 2014 8:32 PM

All replies

  • Please show the declaration of the variable outlookMessages. It should be Variant or of the MailItem type.

    Happy to help ! When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answered

    Friday, March 14, 2014 3:17 PM