Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如果olMail.Body=str1+str2,则更改olMail.Body字体名称和字体大小_Vba_Excel - Fatal编程技术网

Vba 如果olMail.Body=str1+str2,则更改olMail.Body字体名称和字体大小

Vba 如果olMail.Body=str1+str2,则更改olMail.Body字体名称和字体大小,vba,excel,Vba,Excel,这是我的密码 Dim str1 As String Dim str2 As String Dim str3 As String Dim str4 As String Dim olApp As Outlook.Application Set olApp = CreateObject("Outlook.Application") Dim olMail As Outlook.MailItem Set olMail = olApp.CreateItem(olMailItem) olMail.To

这是我的密码

Dim str1 As String
Dim str2 As String
Dim str3 As String
Dim str4 As String

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = reviewer_email_id
olMail.Subject = "Task for Review"
olMail.BodyFormat = olFormatHTML
str1 = "Dear Mr. " & reviewer & ", " & vbNewLine & vbNewLine & "Please see below details for review (Workbook attached)." & vbNewLine & vbNewLine
str2 = "Task : " & title & vbNewLine & "Location : " & document_location & vbNewLine & "Start Date : " & start_date & vbNewLine & "End Date : " & end_date & vbNewLine & vbNewLine
str3 = "Await your Feedback." & vbNewLine & vbNewLine
str4 = "Regards " & vbNewLine & assigned_to
olMail.HTMLBody = "<BODY style=font-size:10pt;font-family:Verdana>str1 + str2 + str3 + str4</BODY>"

olMail.send
发送此电子邮件时,将打印str1+str2+str3+str4作为输出,字体为Verdana,大小为10。而且,当我删除body标记并将olMail.HTMLBody更改为olMail.body时,它会打印str1、str2、str3和str4的值,但不会再更改字体大小和系列

我想打印存储在str1、str2、str3和str4中的值,而不是变量名,还想更改字体系列和大小

是否可以更改olMail.Body的字体大小和字体系列

我使用&表示的变量是我从excel工作表中获得的值。它工作得很好。只希望将字体大小和字体系列分别更改为10和Verdana。
谢谢。

问题是由于没有将变量置于双引号之外以获取其值而导致的

输入:

"<tag>str1 + str2</tag>"
输出:

<tag>str1 + str2</tag>
为了获得变量str1、str2、。。。在邮件正文中并保持格式,您必须执行以下操作:

Dim str1 as String, str2 as string, str3 as String, str4 as String

str1 = "value1 "
str2 = "value2 "
str3 = "value3 "
str4 = "value4"

olMail.HTMLBody = "<BODY style=font-size:10pt;font-family:Verdana>" & str1 + str2 + str3 + str4 & "</BODY>"
将产生:

<BODY style=font-size:10pt;font-family:Verdana>value1 value2 value3 value4</BODY>

在Win10和Outlook 2016上测试。

vbNewLine在HTML中不表示任何内容,无论是使用还是。然后&str1&str2&str3&str4&非常感谢。成功了。