locked
Macro to insert text at the cursor position in outlook 2010 RRS feed

  • Question

  • I have been scanning various forums for VBA code to insert some text into an email at the cursor position. I found this code on a previous post in this forum and it works great for inserting a single line of text but I need to modify it to insert a paragraph of text. Can anyone assist me with the correct code for this macro? 

    Here is the code I am starting with:

    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

    I want to insert the following lines formatted as a paragraph. 

    Hello (name),

     

    Thank you for your e-mail.  A new membership card will be sent to your home address within the next two weeks.

    Should you have any questions or require any additional information, please do not hesitate to contact me. My numbers are listed below.

     

    Regards



    Wednesday, January 16, 2013 4:00 PM

Answers

  • Try chaning sText to this

    Dim sText As String
    sText = "Hello," & Chr(10) & Chr(10) & _
    "Thank you for your e-mail.  A new membership card will be sent to your home address within the next two weeks." & Chr(10) & Chr(10) & _
    "Should you have any questions or require any additional information, please do not hesitate to contact me. My numbers are listed below." & Chr(10) & Chr(10) & _
    "Regards, "

    • Marked as answer by OSSTF_IT Thursday, January 17, 2013 2:31 PM
    Wednesday, January 16, 2013 9:59 PM

All replies

  • Try chaning sText to this

    Dim sText As String
    sText = "Hello," & Chr(10) & Chr(10) & _
    "Thank you for your e-mail.  A new membership card will be sent to your home address within the next two weeks." & Chr(10) & Chr(10) & _
    "Should you have any questions or require any additional information, please do not hesitate to contact me. My numbers are listed below." & Chr(10) & Chr(10) & _
    "Regards, "

    • Marked as answer by OSSTF_IT Thursday, January 17, 2013 2:31 PM
    Wednesday, January 16, 2013 9:59 PM
  • Thank You Bernie. That works perfectly. Much appreciated. 
    Thursday, January 17, 2013 2:32 PM