我有以下代码。因为我使用的是.HTMLBody,所以我需要在VBA中使用HTML标记。电子邮件的收件人将在电子邮件的正文中看到可点击的值(通过代码中的“ AHREF”进行超链接)。单击后,将打开一个新组成的电子邮件,在“收件人”,“主题”和“正文”字段中有一些基本的预填充文本。
在“正文”字段中,我希望引用放置在原始Excel工作表中Range(“ A6”)中的“ VOLUME:”之后的值。每次更改Range(“ A6”)中的值时,都会再次发送电子邮件。收件人将再次单击超链接,并且应该看到与前一封电子邮件相比已更改的值。这可能吗?
Sub Test()
Dim oApp As Object
Dim oEmail As Object
Dim Header As String
Dim Alpha As String
Dim olkPA As Outlook.PropertyAccessor
Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001F"
Header = "<html>" & "<table cellpadding= 5>" & "<tr bgcolor=""#000080"">"
& "<font color =""white"";font face =Calibri><b>" & "<td width = 250>" &
Range("A5") & "</td>" & _
"<td align=""center"";td width= 60>" & Range("E5") & "</td>" & "</font>
</b>" & "</tr>" & "</html>"
Alpha = "<tr bgcolor=""#F0F0F0"">" & "<font face =Calibri>" & "<td>" &
Range("A6") & "</td>" & "<td align=""center"">" & "<A HREF='mailto:
xxx@xxx.com&subject=***ENQUIRY***&Body=INSTRUCTION: EXTEND %0D%0DVOLUME:
1000 %0D%0DCODE: 12345 '>" & _
"<font color =""blue"">" & Range("E6") & "</td>" & "</A>" & "</font>"
& "</tr>" & "</html>"
Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(0)
Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
.To = ""
.CC = ""
.BCC = "xxx@xxx.com"
.Subject = "Test"
.HTMLBody = Header & Alpha
.Display
End With
Set oEmail = Nothing
Set oApp = Nothing
Set colAttach = Nothing
Set oAttach = Nothing
End Sub
答案 0 :(得分:0)
假设您希望使用A6中的值来代替当前的1000,那么您应该能够使用对Range(“ A6”)的引用构造超链接字符串,就像在其他部分中一样整体html字符串:
std::string str = "this essay needs each word to be numbered";
int num = 1;
std::istringstream istr(str);
std::string temp;
std::vector<std::string> substrs;
while (istr >> temp)
{
substrs.push_back(temp);
}
std::stringstream ostr;
for (auto&& substr : substrs)
{
ostr << substr << std::to_string(num++);
}