如何使用VBA将文本插入Outlook电子邮件编辑器 [英] How to insert text into Outlook email editor using VBA

查看:630
本文介绍了如何使用VBA将文本插入Outlook电子邮件编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望创建一个宏,将日期插入到当前处于编辑状态的电子邮件正文中,然后再发送.

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

我正在Windows 7计算机上使用Outlook 2013.

I am using Outlook 2013 on a Windows 7 machine.

所需的工作流程:

  • 点击回复电子邮件
  • 在电子邮件编辑器中,将文本光标置于电子邮件正文内所需的位置以插入文本
  • 执行宏(通过单击电子邮件编辑器窗口的快速访问工具栏中的图标).宏将插入日期.

(假设日期已存储为字符串变量,即宏仅将变量插入到电子邮件正文中的所需位置).

(Assume the date has been stored as a string variable, i.e. the macro simply inserts a variable into the email body at a desired position).

我发现的所有将文本插入电子邮件正文的Outlook VBA示例都涉及将活动电子邮件的HTMLBody存储为字符串,将所需文本附加到该字符串,然后创建全新的电子邮件,然后重新填充到cc ,密件抄送,主题和htmlbody.我希望避免这种情况,因为它看起来很笨拙.

All Outlook VBA examples I have found for inserting text into an email body involve storing the active email's HTMLBody as a string, appending the desired text to that string, then creating a brand new email, and re-populating the to, cc, bcc, subject and htmlbody. I wish to avoid this, as it seems very clunky.

预先感谢您的帮助.

推荐答案

Inspector.WordEditor属性(Outlook)

Application.ActiveInspector方法(Outlook)

示例

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



对Microsoft Word xx.x对象库的引用


Reference to Microsoft Word xx.x Object Library

通过按 "Alt + F11" 键或单击开发人员"功能区中的 "Visual Basic" 按钮,转到Outlook VBA编辑器.

  • 1..在VBA编辑器窗口中,单击菜单栏中的工具"按钮.

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

2..然后,从下拉列表中选择参考"选项.

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

  • 3..在对话框中,您可以向下拉下拉滚动条,直到找到所需的内容,例如"Microsoft Word XX.X对象库".
  • 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".

这篇关于如何使用VBA将文本插入Outlook电子邮件编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆