VBA:更改 Outlook "From" 和字体大小
VBA: Change Outlook "From" and font size
我正在尝试从 VBA Excel 发送 Outlook 电子邮件。据我所知,我已经正确声明了所有内容。我在更改发件人和字体大小时遇到问题。
发件人是辅助电子邮件,也在 Outlook 上,我可以访问。
字体问题是使用以下代码时我似乎无法实现字体大小 11。
发件人:
With OutMail
.Display
.Sender = "someone@example.com"
'.SentOnBehalfOfName = "someoneelse@example.com"
.To = origintext
.Subject = "Location Verification"
.BodyFormat = 2 'olFormatHTML
.HTMLBody = fMsg & fMsg2 & fMsg3 & signature
'.Body = signature
.Display
End With
其中 fMsg
、fMsg2
和 fMsg3
是字符串。签名在代码的前面声明为:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
OutMail.Display
signature = OutMail.HTMLBody
我这样做是为了获得签名,因为似乎无法使用诸如 OutMail.Signature = *Signature1*
.
之类的东西
我知道有一个 OutMail.SentOnBehalfOf = hello@world.com
但它似乎不适用于 OutMail.BodyFormat = 2
它将正文设置为 HTML 格式。
字体:
我的HTML正文示例如下:
fMsg = "<p><font face = ""Calibri(Body)"" font size=""3"" color=""black"">Hello,</font></p>"
然而,随之而来的问题是 font size=""3""
实际上并没有给出 3 号字体,它给出了 10 号字体。我正试图达到 11。font size=""4""
产生 13.5 号字体.
TL;DR:
从我的第二个电子邮件帐户发送 Outlook 电子邮件的 VBA 代码是什么?
使用 HTML 格式获取字体大小 11 的 VBA 代码是什么?
MailItem class 的 SendUsingAccount 属性 允许设置一个 Account 对象,代表发送 MailItem 所使用的帐户。例如:
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone@example.com")
oMail.Recipients.ResolveAll
oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
尝试使用 Word 对象模型更改电子邮件中的字体大小。有关详细信息,请参阅 Chapter 17: Working with Item Bodies。
SentOnBehalfOfName 有点棘手。当它先于显示时,请在此处查看它的工作位置。 SentOnBehalfOf not working in Excel 2010 VBA Code
您可以按照此处所述使用 "style=font-size:11pt" Change HTML email body font type and size in VBA
我正在尝试从 VBA Excel 发送 Outlook 电子邮件。据我所知,我已经正确声明了所有内容。我在更改发件人和字体大小时遇到问题。
发件人是辅助电子邮件,也在 Outlook 上,我可以访问。 字体问题是使用以下代码时我似乎无法实现字体大小 11。
发件人:
With OutMail
.Display
.Sender = "someone@example.com"
'.SentOnBehalfOfName = "someoneelse@example.com"
.To = origintext
.Subject = "Location Verification"
.BodyFormat = 2 'olFormatHTML
.HTMLBody = fMsg & fMsg2 & fMsg3 & signature
'.Body = signature
.Display
End With
其中 fMsg
、fMsg2
和 fMsg3
是字符串。签名在代码的前面声明为:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
OutMail.Display
signature = OutMail.HTMLBody
我这样做是为了获得签名,因为似乎无法使用诸如 OutMail.Signature = *Signature1*
.
我知道有一个 OutMail.SentOnBehalfOf = hello@world.com
但它似乎不适用于 OutMail.BodyFormat = 2
它将正文设置为 HTML 格式。
字体:
我的HTML正文示例如下:
fMsg = "<p><font face = ""Calibri(Body)"" font size=""3"" color=""black"">Hello,</font></p>"
然而,随之而来的问题是 font size=""3""
实际上并没有给出 3 号字体,它给出了 10 号字体。我正试图达到 11。font size=""4""
产生 13.5 号字体.
TL;DR:
从我的第二个电子邮件帐户发送 Outlook 电子邮件的 VBA 代码是什么?
使用 HTML 格式获取字体大小 11 的 VBA 代码是什么?
MailItem class 的 SendUsingAccount 属性 允许设置一个 Account 对象,代表发送 MailItem 所使用的帐户。例如:
Sub SendUsingAccount()
Dim oAccount As Outlook.account
For Each oAccount In Application.Session.Accounts
If oAccount.AccountType = olPop3 Then
Dim oMail As Outlook.MailItem
Set oMail = Application.CreateItem(olMailItem)
oMail.Subject = "Sent using POP3 Account"
oMail.Recipients.Add ("someone@example.com")
oMail.Recipients.ResolveAll
oMail.SendUsingAccount = oAccount
oMail.Send
End If
Next
End Sub
尝试使用 Word 对象模型更改电子邮件中的字体大小。有关详细信息,请参阅 Chapter 17: Working with Item Bodies。
SentOnBehalfOfName 有点棘手。当它先于显示时,请在此处查看它的工作位置。 SentOnBehalfOf not working in Excel 2010 VBA Code
您可以按照此处所述使用 "style=font-size:11pt" Change HTML email body font type and size in VBA