我有Excel VBA代码,可以在组收件箱子文件夹中搜索具有匹配主题的第一封电子邮件。然后它回答所有人。
我无法将我的文本添加到电子邮件的其余部分。
我看到过许多类似问题的响应都显示为.HTMLBody = "test" & .HTMLBody
,但当调试到达这一行时,第二个.HTMLBody
显示为
应用程序定义或对象定义错误
Sub Find_Email()
Dim olMail As Outlook.MailItem
Dim olReply As Outlook.MailItem
Dim olItems As Outlook.Items
Dim olNS As Namespace
Dim olMailbox As Folder
Dim olFolder As Folder
Dim subFolder As Folder
Dim BodyText As String
Set olNS = GetNamespace("MAPI")
Set olMailbox = olNS.Folders("Group_Inbox")
Set olFolder = olMailbox.Folders("test_Folder")
Set subFolder = olFolder.Folders("test_subFolder")
Set olItems = subFolder.Items
TheDate = Format(Date, "DD-MM-YYYY")
TheDate1 = Format(Date, "YYYY-MM")
TheDate2 = Format(Date, "YYYYMMDD")
TheDate3 = Format(Date, "YYYY")
'Find most recent email and populate
olItems.Sort "ReceivedTime", True
For i = 1 To olItems.Count
Set olMail = olItems(i)
If InStr(olMail.Subject, "Desired_Subject " & TheDate) > 0 Then
Set olReply = olMail.ReplyAll
With olReply
.Display
.To = "Recipients@gmail.com"
.CC = ""
.Subject = "Test_Subject"
'.Attachments.Add "Document_destination"
.BodyFormat = olFormatHTML
.HTMLBody = "This is a test email sending in Excel" & .HTMLBody ' This is the problem line.
Exit Sub
End With
End If
Next i
End Sub
我知道这可能是因为它在一个小组的收件箱里,这意味着它可能对你有用。
2条答案
按热度按时间xggvc2p61#
试试这个(我不能测试它,只是一个想法)
qvk1mo1f2#
在环境中引用Outlook对象时可能需要多加小心。