【发布时间】:2021-06-22 10:00:31
【问题描述】:
我想从 excel 发送 Outlook 电子邮件。
我需要在 HTML 代码中插入今天的日期。
尝试格式化日期时,电子邮件正文中的“strDate” 不起作用。
我尝试了替换函数、格式(日期)等方式。
Sub SharePerformance1()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xOutMsg As String
Dim strDate As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
strDate = Format(Date, "dd mmm yyyy")
xOutMsg = "Good morning!<br />This pay period is from <b><span style=""color:#CE0426"">&strDate&</span style=""color:#CE0426""></b>To help ensure you are paid accurately and timely, please follow the instructions below.<br /><br />" & _
"<u>Salaried team members</u><br />" & _
"<span style=font-size:5px>●</span> Reason e.g. sick, vacation, jury duty<br /><br />" & _
"Thank you!"
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Notice" & Format(Now() + 1, "dddd, mmmm dd") & " for Pay Period " & Format(Now() - 8, "dd") & "-" & Format(Now() + 3, "dd/yyyy")
.HTMLBody = xOutMsg
.Display
End With
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
【问题讨论】:
-
不起作用是什么意思?其他一切正常吗?
-
"strDate" 应显示为当前日期,例如“03/25/2021”。但是当我尝试运行代码时,它反而显示了“strDate”这个词。如果我不使用 HTML 着色或仅运行它,它可能会显示“03/25/2021”。
-
你有
strDate内引号而不是外引号。可能已发布的解决方案之一将引导您朝着正确的方向前进。