Consulting

Results 1 to 3 of 3

Thread: Select Text in Outlook Message and Italicize it

  1. #1

    Select Text in Outlook Message and Italicize it

    Hi Everyone! I researched everywhere on this site to at least grab some snippets of code for my task and couldn't find anywhere.

    I'm trying to create a macro: I Place the cursor next to a line of text, I run macro, macro will select entire line of text (same as SHIFT+DOWN), then italicize it.

    The idea here is that I have a lot of meeting notes and lots of titles, so would be nice to run macro that selects text and italicize it based on where i place my cursor.

    This Macro would run inside an Outlook New Email window where you edit text and send it off.

    Thank you so much for your help and input!
    Outlook 2016/2019 . Win 10

    Example:

    James E Brown <---- (I would place cursor right before James and run macros, macros would select entire name and italicize it)
    -During the meet it was discussed blah blah blah

  2. #2
    So Far I have this. It selects the line of text, but does not turn it into italics.

    Public Sub FormatSelectedText()
    Dim objItem As Object
    Dim objInsp As Outlook.Inspector



    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next



    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


    objSel.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    objSel.Font.Italic = wdToggle




    End If
    End If
    End If

    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing
    End Sub

  3. #3
    Actually I figured it out.

    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

    '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


    objSel.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    objSel.Font.Italic = True




    End If
    End If
    End If

    Set objItem = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    Set objInsp = Nothing
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •