VBA Code to select Sender and Signature

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-30 04:44:05

问题


In Excel I'm using code like this to begin an e-mail message through 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

Normally, when I send a (manual) e-mail, I can choose to send it from an address other than my normal one (by pressing the "From" button).

Also, I can choose from one of several signatures I have saved.

How can I accomplish these feats in VBA code?


回答1:


Change 1 to the account number from which you want to send

.SendUsingAccount = OutApp.Session.Accounts.Item(1)

As far as the signatures are concerned, they are stored in %USERPROFILE%\Application Data\Microsoft\Signatures you can loop through the signatures and choose the relevant one




回答2:


Set the MailItem.SendUsingAccount property, call Display (at that point Outlook will insert the signature), read the HTMLBody property (it will now contain the signature), merge it with your own data (note that 2 HTML strings cannot be simply concatenated), set the HTMLBody property.



来源:https://stackoverflow.com/questions/38858472/vba-code-to-select-sender-and-signature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!