我正在写宏找到一封电子邮件并回复它。问题是我要回复的文本没有添加。你能告诉我我做错了吗?
Sub Test()
Dim olApp As Object
Dim olNs As Object
Dim Fldr As Object
Dim i As Long
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Test")
i = 1
For Each olMail In olNs.Items
If InStr(olMail.Subject, "kanapka") <> 0 Then
With olMail.ReplyAll
.CC = "xyz@xyz"
.Body = "Dear All," _
& vbCrLf & "aaaaaa" 'these two lines should add
olMail.Reply.Display
End With
i = i + 1
End If
Next olMail
End Sub
答案 0 :(得分:0)
尝试将此添加到您的代码中:
For Each olMail In olNs.Items
If InStr(olMail.Subject, "testme") <> 0 Then
Set oReply = olMail.Reply
Set oRecip = oReply.Recipients.Add("x@y.z")
oRecip.Type = olCC
oReply.HTMLBody = "Thank you!!!" & oReply.HTMLBody
oReply.Display
Stop ' - remove this once you try the code.
End If
Next olMail
如您所见,您必须将oReply
和oRecip
声明为对象,但这两个让您的生活变得更加轻松。
为了在答案中添加一些文本,只需以这种方式递增主体:
oReply.HTMLBody = "Thank you!!!" & oReply.HTMLBody
我还在您的代码中添加了Stop
,以确保它不会显示大量电子邮件。