1

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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
crashwap
  • 2,846
  • 3
  • 28
  • 62
  • Set email = ActiveInspector.currentItem – niton Feb 01 '17 at 21:30
  • The tiny text below your code says you cannot send emails you composed; you must edit an existing email. Your code edits the first or only selected email directly. Have you tried creating a copy of the original email and editting the copy? Add `Dim emailCopy As MailItem` and `Set emailCopy = email`. – Tony Dallimore Feb 01 '17 at 21:49
  • About not being able to compose new emails - have you tried using Outlook in safe mode `outlook.exe /safe`? It could be some Outlook Addin. – PatricK Feb 02 '17 at 00:13

1 Answers1

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

Community
  • 1
  • 1
crashwap
  • 2,846
  • 3
  • 28
  • 62