我正在尝试从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。< / p>
TL; DR:
从我的第二个电子邮件帐户发送Outlook电子邮件的VBA代码是什么?
使用HTML格式获取字体大小11的VBA代码是什么?
答案 0 :(得分:1)
SentOnBehalfOfName有点棘手。在显示之前,请在此处查看其工作原理。 SentOnBehalfOf not working in Excel 2010 VBA Code
你可以使用&#34; style = font-size:11pt&#34;如此处所述Change HTML email body font type and size in VBA
答案 1 :(得分:0)
MailItem类的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。