Friday, November 8, 2013

Add Dynamic Text in Outlook Mail


This code will help to create a Macro that will be use for repeated input text.

Sub myMacro1()

Dim sText As String
sText = "Hi," & Chr(10) & Chr(10) & _
"This is a Macro Use in Outlook Mail" & Chr(10) & Chr(10) & _
"Enjoy Coding:" & Chr(10) 

PrintTextToBody (sText)
End Sub

Sub PrintTextToBody(ByVal sText As String)
On Error GoTo ErrHandler
If TypeName(ActiveWindow) = "Inspector" Then
    If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
        ActiveInspector.WordEditor.Application.Selection.TypeText sText
    End If
End If
Exit Sub
ErrHandler:
Beep
End Sub