【发布时间】:2017-09-22 18:57:22
【问题描述】:
我想让两个字符串变量出现在电子邮件的正文中。我知道我们可以定义一个正文,然后将该正文作为一个整体插入。我想更进一步,在文本中插入两个项目,并且不显示为 VBA,而是显示为实际名称。
这两个字符串变量是电子邮件的前两个收件人的名字,在这种情况下,在 VBA 中命名为 strTO 和 strTO1。当前宏创建一个回复并将它们插入到问候语中。我也想让它们出现在正文中。
示例:收件人姓名分别是 Tom Jones 和 Severus Snape,strTO 和 strTO1。我将它们插入文本中,如下所示:
strbody = "<H2><Font Face=calibri>Good Day, </H2>" & strTO & _
"Please review your data below (link) and approve.<br>" & _
"Pleaes contact strTO1 if you have problems.<br>" & _
"<A HREF=""http://www.google.com.htm"">Click Here</A>" & _
"<br><br><B>Thank you</B>"
我希望它在运行宏时读取的内容(粗体仅用于本文的目的):
美好的一天,汤姆。
请在下方查看您的数据(超链接)并批准。
如果您有问题,请联系 Severus。
(显示“单击此处”的超链接)
谢谢
现在发生的事情(Blank 表示只是一个空格):
美好的一天空白,
请在下方查看您的数据(显示“单击此处”的超链接)并批准。
如有问题,请联系 strTO1。
谢谢
我希望我可以使用某种标签来插入 strTO 和 strTO1。
以下是包含上述代码的整个宏:
Sub AutoReply()
Dim oMail As MailItem
Dim oReply As MailItem
Dim GreetTime As String
Dim strbody As String
Dim SigString As String
Dim signature As String
Dim strGreetNameAll As String
Dim lastname As String
Dim strgreetname As String
Dim R As Long
Dim text
Dim strTo As String
Dim strTo1 As String
Select Case Application.ActiveWindow.Class
Case olInspector
Set oMail = ActiveInspector.CurrentItem
Case olExplorer
Set oMail = ActiveExplorer.Selection.Item(1)
End Select
strbody = "<H2><Font Face=calibri>Good Day, </H2>" & <strTo> & _
"Please review your data below and approve.<br>" & _
"Please contact strTO1 if you have problems.<br>" &
"<A HREF=""http://www.google.com.htm"">Click Here</A>" & _
"<br><br><B>Thank you</B>"
SigString = Environ("appdata") & _
"\Microsoft\Signatures\90 Days.htm"
If Dir(SigString) <> "" Then
strGreetName1 = Left$(oMail.SenderName, InStr(1, oMail.SenderName, " ") - 1)
lastname = Right(oMail.SenderName, Len(oMail.SenderName) - InStr(1, oMail.SenderName, " "))
If Dir(SigString) <> "" Then
signature = GetBoiler(SigString)
Else
signature = ""
End If
Set oReply = oMail.ReplyAll
Select Case Application.ActiveWindow.Class
Case olInspector
Set oMail = ActiveInspector.CurrentItem
Case olExplorer
Set oMail = ActiveExplorer.Selection.Item(1)
End Select
With oReply
For R = 1 To .recipients.Count
Debug.Print .recipients(R)
strgreetname = Left$(.recipients(R), InStr(1, .recipients(R), " "))
strGreetName2 = Left$(.recipients(2), InStr(1, .recipients(R), " "))
strGreetNameAll = strGreetNameAll & strgreetname
strGreetNameAll1 = strgreetname
strTo = Left(strGreetNameAll, InStr(.recipients(R), " "))
strTo1 = Left(strGreetName2, InStr(1, .recipients(R), " "))
strTo = Left(.recipients(1), InStr(.recipients(1) & " ", " ") - 1)
If .recipients.Count > 1 Then
strTo1 = Left(.recipients(2), InStr(.recipients(2) & " ", " ") - 1)
Else
strTo1 = ""
End If
Next R
Debug.Print strGreetNameAll
strGreetNameAll = Left(strGreetNameAll, Len(strGreetNameAll) - 1)
Debug.Print strGreetNameAll
.HTMLBody = "<Font Face=calibri>Dear " & strTo & " and " & strTo1 & ", " & strbody & "<br>" & signature
.Display
End With
End If
End Sub
【问题讨论】:
-
关于这个网站的一件事我不明白......每当我发布赞美你们所有人并赞扬所有人的东西时,人们想要编辑它吗?如果我这样做会很糟糕吗?你们都知道这么多,帮助这么多人学习,你应该为此受到表扬!如果不合适,我不会这样做。我只是想表达我的感激之情。