locked
Macro to add text to cursor position in outlook 2010 email RRS feed

  • Question

  • Hi,

    I would like to write a macro to insert a text in a message body. The text will be added to the current cursor position.

    Thanks,

     


    Guy Zommer
    Thursday, December 1, 2011 5:22 AM

Answers

  • In the absence of any information about how and when this is going to be used, the following Outlook macro will type the text string "Enter this text at the cursor" at the cursor

     

    Sub InsertText()
    Const sText As String = "Enter this text at the cursor"
    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


    Graham Mayor - Word MVP
    www.gmayor.com
    • Marked as answer by Guy Zommer Thursday, December 1, 2011 10:34 AM
    Thursday, December 1, 2011 10:14 AM

All replies

  • In the absence of any information about how and when this is going to be used, the following Outlook macro will type the text string "Enter this text at the cursor" at the cursor

     

    Sub InsertText()
    Const sText As String = "Enter this text at the cursor"
    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


    Graham Mayor - Word MVP
    www.gmayor.com
    • Marked as answer by Guy Zommer Thursday, December 1, 2011 10:34 AM
    Thursday, December 1, 2011 10:14 AM
  • This works fine. How to add any image with the same text ?
    Tuesday, February 6, 2018 8:43 PM
  • It would have been better had you started a new thread, however, which image do you want to add and where in relation to they inserted text?

    There surely has to be more to this question than is written as it would be simpler to simply use the tools Outlook provides to select and insert an image.


    Graham Mayor - Word MVP
    www.gmayor.com

    Wednesday, February 7, 2018 8:18 AM