问题
For valid personal reasons** I am trying to construct a macro that clears out the To, CC, Subject and Body of the email being replied to (in compose mode?). What I have below works on an email being READ, but it does not work on an email being MODIFIED/COMPOSED.
What must be changed for the macro to work on an email being composed/edited?
Sub ClearEmail()
Dim olExplorer As Explorer
Dim olSelection As Selection
Dim email As MailItem
Dim strSig As String, Sig As String
Set olExplorer = Application.ActiveExplorer
Set olSelection = olExplorer.Selection
Set email = olSelection.Item(1)
email.To = ""
email.CC = "team@example.com"
email.Subject = ""
email.HTMLBody = vbCrLf & vbCrLf & vbCrLf & "Hello"
End Sub
**My Exchange profile is messed up, has been for weeks, and the part-time Exchange admin cannot get to it anytime soon. The only way I can successfully send an email is to open an existing email from the group Inbox, hit Reply To All, clear out the fields and add my signature. Then I can edit as desired and send it with no problems. (Emails I simply compose and send get stuck in the Outbox and are never sent - there are dozens of them.) I have been doing this manually for weeks.
I am not an Outlook/VBA programmer so please forgive me for not knowing the right terminology.
Sources:
http://www.rondebruin.nl/win/s1/outlook/signature.htm
http://www.vbforums.com/showthread.php?628044-Insert-text-into-current-outlook-message
回答1:
This allows editing the email currently being composed:
Dim theEmail As MailItem, oInspector As Inspector
Set oInspector = Application.ActiveInspector
Set theEmail = oInspector.CurrentItem
Reference:
Working with current open email
来源:https://stackoverflow.com/questions/41989779/outlook-programmatically-modify-email-currently-being-composed-edited