tarun_shetty
New Member
- Joined
- Apr 18, 2013
- Messages
- 1
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
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