2
(Note: I've never messed with VBA before; sorry for probably terrible code!)
I'm trying to make a macro that first removes paragraphs containing specific terms (hardcoded into the macro), then sets the email type to HTML, and inserts the default signature at the end.
I'm stuck on one final issue: When I use InsertFile, it replaces the entire email with the signature instead of appending it. Any ideas?
Sub Function()
'Import Word functions and search & remove
Dim Ins As Outlook.Inspector
Dim Document As Word.Document
Dim Word As Word.Application
Dim Selection As Word.Selection
Set Ins = Application.ActiveInspector
Set Document = Ins.WordEditor
Set Word = Document.Application
Set Selection = Word.Selection
Dim search As String
search = "search term 1"
Dim search2 As String
search2 = "search term 2"
Dim para As Paragraph
For Each para In Document.Paragraphs
Dim txt As String
txt = para.Range.Text
If InStr(txt, search) Or InStr(txt, search2) Then
para.Range.Delete
End If
Next
'Set to HTML
Dim objItem As Object
Dim objMail As MailItem
On Error Resume Next
Set objItem = Application.ActiveInspector.CurrentItem
If Not objItem Is Nothing Then
If objItem.Class = olMail Then
ActiveInspector.CommandBars.ExecuteMso ("MessageFormatHtml")
End If
End If
'Get and insert default HTML signature
Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "*.htm")
Else:
Signature = ""
End If
Document.Range.InsertParagraphAfter
Document.Range.InsertFile Signature, , False, False, False
End Sub
take a look here – Raystafarian – 2014-12-16T12:34:42.270