PDA

View Full Version : outlook VBA Code: to reply, change subject, remove body and insert "quick part"



snoopyb98
06-17-2011, 01:02 PM
I'm trying to get a working Macro to do the following:
Reply to an email, changes the subject, removes the body text and inserts a quick part.
This is for outlook 2007 or 2010.

i've had this much, but can't seem to get the seams right:

Sub MinistryOpening()
'
' MinistryOpening Macro
Dim obj As Object
Dim oReply As Outlook.MailItem
Dim objOL As Outlook.Application

Const FIX_SUBJECT As String = "RE: New Subject Text"
Select Case True
Case TypeOf Application.ActiveWindow Is Outlook.Inspector
Set obj = Application.ActiveInspector.CurrentItem
Case Else
With Application.ActiveExplorer.Selection
If .Count Then
Set obj = .Item(1)
End If
End With
If TypeOf obj Is Outlook.MailItem Then
Set oReply = obj.Reply
If InStr(1, oReply.Subject, FIX_SUBJECT, vbTextcompare) = 0 Then
oReply.Subject = FIX_SUBJECT
oReply.Display
Application.ActiveInspector.CurrentItem.BodyFormat = olFormatHTML
End If
End If
End Select
End Sub
Sub InsertQuickPart(Quickpartname As String)
Dim objOL As Outlook.Application
Dim objDoc As Word.Document
Dim objWord As Word.Application
Dim objSel As Word.Selection
Dim objETemp As Word.Template
On Error Resume Next

Set objOL = Outlook.Application
Set objDoc = objOL.ActiveInspector.WordEditor
Set objWord = objDoc.Application
Set objSel = objDoc.Windows(1).Selection
Set objETemp = objWord.Templates(1)
objETemp.BuildingBlockEntries(Quickpartname).Insert _
Where:=objSel.Range, RichText:=True

Set objOL = Nothing
Set objDoc = Nothing
Set objWord = Nothing
Set objSel = Nothing
Set objETemp = Nothing

End Sub

Any help would be appreciated. Thanks!