【问题标题】:VBA: Change Outlook "From" and font sizeVBA:更改 Outlook“发件人”和字体大小
【发布时间】:2015-07-03 09:14:41
【问题描述】:

我正在尝试从 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

其中fMsgfMsg2fMsg3 是字符串。签名在代码的前面声明:

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
OutMail.Display
signature = OutMail.HTMLBody

我这样做是为了获得签名,因为似乎不可能使用诸如 OutMail.Signature = *Signature1* 之类的东西。

我知道有一个 OutMail.SentOnBehalfOf = hello@world.com,但这似乎不适用于将正文设置为 HTML 格式的 OutMail.BodyFormat = 2


字体:

我的 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 代码是什么?

【问题讨论】:

  • @JasonMArcher 感谢您的保存!看起来我错过了一些东西。

标签: vba excel fonts outlook


【解决方案1】:

SentOnBehalfOfName 有点棘手。在这里查看它在显示之前的工作位置。 SentOnBehalfOf not working in Excel 2010 VBA Code

您可以使用此处描述的“style=font-size:11pt”Change HTML email body font type and size in VBA

【讨论】:

    【解决方案2】:

    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

    【讨论】:

    • 我的线路OutMail.SendUsingAccount = "myname@account.com" 似乎在做它应该做的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多