locked
macro to insert text in Outlook 2007 RRS feed

  • Question

  • Hello,

    I am trying to automate a way to insert text that I have to type all the time in Outlook 2007 messages -- both new and replies.  I tried pasting the word into a macro in Outlook, with no success.

    The text I need to insert often has a symbol in it, such as the word   Máire.   Inserting symbols is a long process in Outlook 2007, so I end up

    pasting from a Notepad file to my message to insert words with accents.         Too slow!

     

    I need the code that'll work with a single word, a group of words, and/or an address (with hard returns).

                                   Thanks for any assistance you can give me.

    Friday, September 23, 2011 5:56 PM

Answers

  • Hi granfors,

     

    I suppose you have Word 2007 on your machine. And I provide the snippet to approach your issue. I hope what I show you can solve your issue.

     

    Sub test()
        Dim olInspector As Outlook.Inspector
        Dim olDocument As Word.Document
        Dim olSelection As Word.Selection
        
        Set olInspector = Application.ActiveInspector()
        Set olDocument = olInspector.WordEditor
        Set olSelection = olDocument.Application.Selection
        
        olSelection.InsertBefore "Hello World!"
        
        olSelection.Collapse wdCollapseEnd
        
        Set olSelection = Nothing
        Set olDocument = Nothing
        Set olSelection = Nothing
        
    End Sub
    

    Have a good day,

     

    Tom

     

     

     


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 29, 2011 6:41 AM

All replies

  • Hi granfors,

     

    Thanks for posting in the MSDN Forum.

     

    I think you need to clarify some options:

     

    1.       Do you want to insert specific string to the end of the mail’s body or the place where the cursor stays?

    2.       Have you installed Word 2007 on your machine?

    3.       Which kind of body content you will insert into Plaint text, rtf or Html?

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 26, 2011 6:55 AM
  • Hi granfors,

     

    I suppose you have Word 2007 on your machine. And I provide the snippet to approach your issue. I hope what I show you can solve your issue.

     

    Sub test()
        Dim olInspector As Outlook.Inspector
        Dim olDocument As Word.Document
        Dim olSelection As Word.Selection
        
        Set olInspector = Application.ActiveInspector()
        Set olDocument = olInspector.WordEditor
        Set olSelection = olDocument.Application.Selection
        
        olSelection.InsertBefore "Hello World!"
        
        olSelection.Collapse wdCollapseEnd
        
        Set olSelection = Nothing
        Set olDocument = Nothing
        Set olSelection = Nothing
        
    End Sub
    

    Have a good day,

     

    Tom

     

     

     


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 29, 2011 6:41 AM