Excel 选择发件人和签名的VBA代码

Excel 选择发件人和签名的VBA代码,excel,vba,outlook,Excel,Vba,Outlook,在Excel中,我使用以下代码通过Outlook开始发送电子邮件: Set mOutlookApp = GetObject("", "Outlook.application") Set OutMail = mOutlookApp.CreateItem(0) With OutMail .To = "blahblah@blah.com" .Subject = "More BLAH here" .HTMLBody = "Message Text" & .HTMLBod

在Excel中,我使用以下代码通过Outlook开始发送电子邮件:

Set mOutlookApp = GetObject("", "Outlook.application")
Set OutMail = mOutlookApp.CreateItem(0)

With OutMail
    .To = "blahblah@blah.com"
    .Subject = "More BLAH here"
    .HTMLBody = "Message Text" & .HTMLBody ' This preserves the Signature in the message.
    .Display
End With
通常,当我发送(手动)电子邮件时,我可以选择从正常地址以外的其他地址发送(通过按“发件人”按钮)

此外,我可以从我保存的几个签名中选择一个


如何在VBA代码中完成这些壮举?

设置
邮件项。SendUsingAccount
属性,调用
显示
(此时Outlook将插入签名),读取
HTMLBody
属性(它现在将包含签名),将其与您自己的数据合并(注意,两个HTML字符串不能简单地连接),设置
HTMLBody
属性

1
更改为要发送的帐号

.SendUsingAccount = OutApp.Session.Accounts.Item(1)
就签名而言,它们存储在
%USERPROFILE%\Application Data\Microsoft\signatures
中。您可以循环浏览签名并选择相关的签名