Outlook - programmatically modify email currently being composed/edited

Deadly 提交于 2020-08-09 09:13:35

问题


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

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