问题
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