Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Japanuspus/dd69437a419577a71406aee2fda0fda1 to your computer and use it in GitHub Desktop.
Save Japanuspus/dd69437a419577a71406aee2fda0fda1 to your computer and use it in GitHub Desktop.
'
' Reply To All in Plain Text, with Linux-style quoting
'
' This allows you to use Outlook to reply to a mailinglist
'
' Copyright 2009 Matthijs van de Water
'
Sub ReplyAllPlain()
Dim app As New Outlook.Application
Dim exp As Outlook.Explorer
Set exp = app.ActiveExplorer
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim item As Outlook.MailItem
'Get MailItem based on EntryID, otherwise we'll get security warnings
strID = exp.Selection.item(1).EntryID
Set olNS = Application.GetNamespace("MAPI")
Set item = olNS.GetItemFromID(strID)
' Store name of the sender and date of sent message
Dim name As String
name = item.SentOnBehalfOfName
datestr = Format(item.SentOn, "DDD, MMM dd, yyyy at HH:mm:ss")
' ReplyToAll to this message in Plain formatting with > style
item.BodyFormat = olFormatPlain
item.Actions("Reply to All").ReplyStyle = olReplyTickOriginalText
Dim rply As Outlook.MailItem
Set rply = item.ReplyAll
' Rebuild original body:
' - Remove Outlook-style reply header
' - Get rid of auto-inserted signature (optionally move to end of message)
orgBody = rply.Body
pos = InStr(orgBody, ">") - 1
sig = Left(orgBody, pos)
myBody = Mid(orgBody, pos + 1)
b = 0
lines = Split(myBody, vbNewLine)
For Each myLine In lines
If b > 4 Then
newBody = newBody & myLine & vbNewLine
End If
b = b + 1
Next
' Put new body together
rply.Body = "On " & datestr & ", " & name & " wrote:" _
& vbNewLine & newBody & vbNewLine '& sig
rply.Display
item.Close olDiscard
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment