使用Excel Visual Basic的电子邮件正文中的粗体变量 [英] Bold Variables in Email body using Excel Visual Basic
本文介绍了使用Excel Visual Basic的电子邮件正文中的粗体变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这实际上是我第一次在这个网站上发布 - 我非常感谢所有的帮助我可以得到!
This is actually my first time posting on this site - I really appreciate all the help I can get!
我有一个包含
- 客户电子邮件,
- 他们的名字,
- 他们的检查日期和
- 及其处理日期。
- clients emails,
- their name,
- their check dates and
- and their processing date.
我想每天向他们发送提醒电子邮件如果他们的处理日期是今天。我已经成功地编写了代码 - 但是我没有能够粗体部分电子邮件( ProcessingDate
, CheckDate
和时间
)。
I want to send out a reminder email to them daily if their processing date is today. I've been successful in writing the code - but I haven't been able to bold parts of the email (ProcessingDate
, CheckDate
and Time
).
再次感谢你!
这是我的代码:
Sub SendEm()
Dim i As Integer, Mail_Object, Email_Subject, o As Variant, lr As Long, MyDate As Date, Client As String, ProcessingDate As Date, CheckDate As Date, Time As Date, PayrollSpecialist As String
Dim Msg As Variant
lr = Sheets("DataSheet").Cells(Rows.Count, "S").End(xlUp).row
Set Mail_Object = CreateObject("Outlook.Application")
MyDate = Date
For i = 2 To lr
Client = Sheets("DataSheet").Range("S" & i).Value
ProcessingDate = Sheets("DataSheet").Range("B" & i).Value
CheckDate = Sheets("DataSheet").Range("C" & i).Value
Time = Sheets("DataSheet").Range("A" & i).Value
PayrollSpecialist = Sheets("DataSheet").Range("D" & i).Value
If Sheets("DataSheet").Range("B" & i).Value = MyDate Then
Msg = "Dear" & " " & Client
Msg = Msg & Sheets("Email").Range("B2").Value
Msg = Msg & ProcessingDate & " "
Msg = Msg & Sheets("Email").Range("B3").Value
Msg = Msg & CheckDate
Msg = Msg & ". " & Sheets("Email").Range("B4").Value & " "
Msg = Msg & Time
Msg = Msg & " " & Sheets("Email").Range("B5").Value & Sheets("Email").Range("B6").Value & vbNewLine & PayrollSpecialist
With Mail_Object.CreateItem(o)
.Subject = Sheets("Email").Range("A2").Value
.To = Sheets("DataSheet").Range("T" & i).Value
.Body = Msg
'.Send
.display 'disable display and enable send to send automatically
End With
End If
Next i
MsgBox "E-mail successfully sent", 64
Application.DisplayAlerts = False
Set Mail_Object = Nothing
End Sub
推荐答案
您可以使用
-
.htmlBody
而不是.Body
- 使用html
.htmlBody
rather than.Body
- use html
所以要加粗 ProcessingDate
Msg = Msg& < B> 中&安培; ProcessingDate& < / b>
例如使用你的代码
Msg = "Dear" & " " & Client
'Msg = Msg & Sheets("Email").Range("B2").Value
Msg = Msg & "<b>" & ProcessingDate & "</b> "
'Msg = Msg & Sheets("Email").Range("B3").Value
Msg = Msg & CheckDate
'Msg = Msg & ". " & Sheets("Email").Range("B4").Value & " "
Msg = Msg & Time
'Msg = Msg & " " & Sheets("Email").Range("B5").Value & Sheets("Email").Range("B6").Value & vbNewLine & PayrollSpecialist
With Mail_Object.CreateItem(o)
.Subject = "tested"
.To = "someone@hotmail.com"
.htmlBody = Msg
'.Send
.display 'disable display and enable send to send automatically
End With
这篇关于使用Excel Visual Basic的电子邮件正文中的粗体变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!