PDA

View Full Version : Add text to email body



tarun.shetty
04-18-2013, 02:34 AM
Here goes,

All I have to do is to add a formatted text (red color) at the beginning of the email body and forward to a particular email address.

I'm stuck in the first part. What I have achieved so far that I have to keep the email open in edit mode. Only then my code adds the formatted text and save the email. Can I achieve this just by keeping the email in active selection? neither do I wish to open the mail in edit or read mode in a separate window.

I just got into macro programming yesterday, so please be patient. But I do have programming background. Any suggestions how I can achieve the first of my problem.


My current code:
Sub AddText()

Dim objItem As Object
Dim objInsp As Outlook.Inspector

' Add reference to Word library
' in VBA Editor, Tools, References
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objSel As Word.Selection
On Error Resume Next

'Reference the current Outlook item
' Set objItem = Application.ActiveExplorer.Selection
Set objItem = Application.ActiveInspector.CurrentItem
If Not objItem Is Nothing Then
If objItem.Class = olMail Then
Set objInsp = objItem.GetInspector
If objInsp.EditorType = olEditorWord Then
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection

With objSel
' Formatting code goes here

Dim Ins As Outlook.Inspector
Dim Doc As Word.Document
Dim Range As Word.Range
Dim Pos As Long

Set Ins = Application.ActiveInspector
Set Doc = Ins.WordEditor
If Not Doc Is Nothing Then
Pos = Doc.Range.End - 1
Set Range = Doc.Range(0, 0)
Range.Select
End If

.Font.Color = wdColorRed
.TypeText Text:="Text Message" & vbNewLine & vbNewLine

End With

End If
End If
End If

' objItem.Save
objItem.Close (olSave)


Set objItem = Nothing
Set objWord = Nothing
Set objSel = Nothing
Set objInsp = Nothing


End Sub

skatonni
04-26-2013, 08:12 PM
For anyone having a similar issue the answer received here was accepted. It may work for you as well. http://answers.microsoft.com/en-us/office/forum/office_2010-customize/how-do-i-append-text-to-the-email-body/00669b79-ef49-4552-a3f1-a6d153e1199c

fyi - Some can be annoyed, and there are very few answerers to begin with. http://www.vbaexpress.com/forum/showthread.php?t=6905