我有一个包含几行文字的字符串元素。如果我将此字符串用作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
答案 0 :(得分:0)
您需要将HTMLBody属性设置为格式正确的HTML文本:
strvar = "<html><body>some <b>bold</b> text<br>and <i>italic</i> too</body></html>"
...
.HTMLBody = strVar
答案 1 :(得分:0)
这是在活动单元格中加粗字符串的代码,如果它包含“@”的话。你需要弄清楚你需要它做什么,但这应该有助于你开始。它现在只适用于活动单元格。
If ActiveCell.Value Like "*@*" Then
ActiveCell.Font.Bold = True
End If