VBA for Outlook中的运行时错误 [英] Runtime error in VBA for Outlook
问题描述
所以我试图在Outlook中编写一个模块,用于解析我在邮件正文中发送的电子邮件中的电子邮件。我得到'运行时424错误'在这行代码
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
它说需要一个对象,我很确定错误是参考 For
每个outlookMessage在outlookFolder.Items
有人可以帮帮我,我对VBA不是很好,我需要一些帮助。
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
如果不是outlookFolder则没有那么
对于 每个 outlookMessage 在 outlookFolder 。 Items
strMsgBody = outlookMessage 。 Body '将消息体指定给Var
'然后使用Sue Moshers代码查找体内的东西
'引号中的所有以下内容""特定于您的需求
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 =")
'添加电子邮件时间戳,只是因为我想要它
strEmailContents = strEmailContents & "," & outlookMessage 。 ReceivedTime & vbCrLf
'调试消息将其注释为生产
'wscript.echo strEmailContents
下一步
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
结束如果
先谢谢你!
Thank you in advanced!
推荐答案
请显示变量outlookMessages的声明。它应该是Variant或MailItem类型。
Please show the declaration of the variable outlookMessages. It should be Variant or of the MailItem type.
这篇关于VBA for Outlook中的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!