Thread: Macro problem
View Single Post
 
Old 08-12-2014, 06:29 AM
niton niton is offline Windows 7 64bit Office 2010 64bit
Competent Performer
 
Join Date: Jul 2012
Posts: 102
niton is on a distinguished road
Default

I did add Dim objSel As Word.Selection. But this may still not be enough.

This link provides details. http://www.slipstick.com/developer/w...outlook-email/

Code:
Public Sub FormatSelectedText()
    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 ' <--- Do not use this unless you have a specific purpose
    
'Reference the current Outlook item 
    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
 
 
' replace the With block with your code
       With objSel
       ' Formatting code goes here
            .Font.Color = wdColorBlue
            .Font.Size = 18
            .Font.Bold = True
            .Font.Italic = True
            .Font.Name = "Arial"
       End With
 
            End If
        End If
    End If
     
    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing
End Sub
Reply With Quote