How to insert text into Outlook email editor using VBA

前端 未结 1 1769
余生分开走
余生分开走 2020-11-29 13:33

I wish to create a macro that inserts the date into an email body which is currently open for editing, prior to sending.

I am using Outlook 2013 on

相关标签:
1条回答
  • InsertBefore Method or InsertAfter Method

    Inspector.WordEditor Property (Outlook)

    Application.ActiveInspector Method (Outlook)

    Example

    Option Explicit
    Public Sub Example()
        Dim Inspector As Outlook.Inspector
        Dim wdDoc As Word.Document
        Dim Selection As Word.Selection
            
    
        Set Inspector = Application.ActiveInspector()
        Set wdDoc = Inspector.WordEditor
        Set Selection = wdDoc.Application.Selection
            Selection.InsertBefore Format(Now, "DD/MM/YYYY")
        
        
        Set Inspector = Nothing
        Set wdDoc = Nothing
        Set Selection = Nothing
    End Sub
    


    Reference to Microsoft Word xx.x Object Library


    Go to Outlook VBA editor either by pressing "Alt + F11" keys or clicking on the "Visual Basic" button in the “Developer” ribbon.

    • 1. In VBA editor window, click the "Tools" button in the menu bar.

    • 2. Then, from the drop down list, select the "References" option.

    • 3. In the dialog box, you can pull the scrolling bar down until you locate what you want, such as "Microsoft Word XX.X Object Library".

    0 讨论(0)
提交回复
热议问题