我的工作代码将浏览移动到指定文件夹的所有传入电子邮件。一旦它在文件夹中,宏将运行以检查我的Excel历史文件中是否存在该电子邮件。
以下代码的工作方式是返回代理商名称的值。但是,它不会在电子邮件中附加该代理的名称。此代码是否适用于在电子邮件正文中添加文本:
emlBody = ActiveAgnt & vbCrLf & emlBody
如果是,那么为什么在电子邮件正文中添加了代理商的名称?以下是其余代码。
Set objFolder = Session.GetDefaultFolder(olFolderInbox).Folders("For Processing")
Set objItems = objFolder.Items
For Each obj In objItems
For lgCurrentRow = 2 To lgLastRow
If obj.Class = olMail Then
strSubj = myXLApp.Worksheets("Sheet1").Cells(lgCurrentRow, "C")
StrSR = myXLApp.Worksheets("Sheet1").Cells(lgCurrentRow, "D")
StrAgnt = myXLApp.Worksheets("Sheet1").Cells(lgCurrentRow, "E")
emlSubj = obj.Subject
emlBody = obj.Body
'>>>>>Check if incoming email has an existing SR in History File<<<<<
If emlSubj Like "*" & strSubj & "*" Then
Debug.Print strSubj
'*****If existing then check if there is an existing SR
'*****Append to email if SR is existing
If StrSR <> "" Then
Debug.Print StrSR
'*****If SR is not existing check if an agent is tagged to the email.
'*****If agent is tagged then append agent's name to email
ElseIf StrAgnt <> "" Then
Debug.Print StrAgnt
End If
Exit For
'^^^^^Check if incoming email has an existing SR in History File^^^^^
'>>>>>If Incoming file is not match Check Active Agents list to assign Agent<<<<<
ElseIf emlSubj <> "*" & strSubj & "*" Then
Call ActiveAgents(ActiveAgnt)
Debug.Print ActiveAgnt
emlBody = ActiveAgnt & vbCrLf & emlBody
'^^^^^If Incoming file is not match Check Active Agents list to assign Agent^^^^^
Exit For
Set obj = Nothing
Set objItems = Nothing
Set objFolder = Nothing
Set objOL = Nothing
Set obj.Body = Nothing
End If
End If
Next
Next
答案 0 :(得分:0)
而不是
obj.Body = ActiveAgnt & vbCrLf & obj.Body
试
{{1}}
答案 1 :(得分:0)
这里有一些包含@niton和@Doug Glancy建议的代码。
ElseIf emlSubj <> "*" & strSubj & "*" Then
Call ActiveAgents(ActiveAgnt)
Debug.Print ActiveAgnt
obj.Body = ActiveAgnt & vbCrLf & obj.Body
obj.Save