所以我想在Outlook中編寫一個模塊,它將解析郵件正文中發送的電子郵件。我得到一個「運行時錯誤424」在這行代碼VBA中的Outlook運行時錯誤
For Each outlookMessage In outlookFolder.Items
它說,對象是必需的,我敢肯定,誤差值在參考For Each outlookMessage In outlookFolder.Items
是否有人可以幫助我出來,我不是很好用VBA,我需要一些幫助
這裏是我講的一個代碼的部分:!
' 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
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
謝謝你在先進
對於每個**項目**在outlookFolder.Items的作品? – Alex
作爲後續從你的'For iCtr = 1..'循環你正在尋找具有特定名稱的文件夾,當這個文件夾沒有找到,你的'outlookFolder'是Nothing。這是錯誤的原因。要處理一個錯誤,你可以添加「if」語句:'如果沒有outlookFolder是Nothing Then'就在'For Each outlookMessage in outlookFolder.Items'和'End If'緊接'Next'後面 –
@simco我應該把什麼放在如果陳述? –