【发布时间】:2018-03-02 02:25:31
【问题描述】:
我有一个包含多行文本的字符串元素。但是,如果我将此字符串用作 Outlook 正文文本,则它们将没有像粗体字体这样的格式到特定行。我想使用这个字符串并将粗体字体应用于特定行(例如,所有包含符号“@”和 for 循环的行)。
在将字符串合并为电子邮件正文之前,如何在代码中实现这一点?我想我必须从中创建一个新对象,然后将其放入电子邮件正文中。
Sub Send_Email()
Dim OutApp As Object
Dim OutMail As Object
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Dim iFile As Integer
Dim strVar As String 'Pre-definition of the input variable
iFile = FreeFile
Open "FILE_PATH" For Input As #iFile
strVar = Input(LOF(iFile), iFile) 'Definition of the input varibale
Close #iFile
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = ""
.BCC = ""
.Subject = ""
.BodyFormat = olFormatRichText
.Body = strVar 'Creation of the e-mail text body
.Display 'Or use .Send
End With
On Error GoTo 0
End Sub
【问题讨论】:
-
我建议您使用 WordEditor 来处理文本。 msdn.microsoft.com/en-us/library/dd492012(v=office.12).aspx