Outlook 2013 中的自动化操作

Automating Actions in Outlook 2013

我在 Outlook 中有一个电子邮件文件夹,我希望能够对文件夹中的每封电子邮件应用相同的操作,但是我注意到 Outlook 的开发人员选项中没有宏记录器。

我目前正在进行的过程包括打开每封电子邮件(因为它包含 HTML 内容并且我想以文档质量图像打印它)从 [=17= 中选择 "View in browser" ] 选项卡,然后从 Internet Explorer 打印。

有没有办法在 Outlook 中为文件夹中的每封电子邮件重复执行此操作?如果没有某种方式来记录我的操作以了解如何引用 Outlook 模块中的内容,我不知道如何设置...

您需要稍微了解一下 Outlook 的对象模型 Getting Started with VBA in Outlook 2010。这里有一些代码可以帮助您入门。此宏将遍历文件夹中的所有项目并检查收件人的电子邮件地址并设置标志

Sub SetFlagIcon()
    Dim mpfInbox As Outlook.Folder
    Dim obj As Outlook.MailItem
    Dim i As Integer
    Set mpfInbox = Application.GetNamespace("MAPI").Folders("Jeanno").Folders("Sent Mail")
    ' Loop all items in the Inbox\Test Folder
    For i = 1 To mpfInbox.Items.Count
        If mpfInbox.Items(i).Class = olMail Then
            Set obj = mpfInbox.Items.Item(i)
            For Each Recipient In obj.Recipients
                If Recipient.Address = "someone@email" Then
                    'Set the yellow flag icon
                    obj.FlagIcon = olYellowFlagIcon
                    obj.Save
                End If
            Next Recipient
        End If
    Next
End Sub

Outlook没有宏录制器,但可以使用Word中录制的宏 由于Outlook使用Microsoft Word作为电子邮件编辑器,开发人员可以使用Word强大的库来编辑电子邮件和其他项目的内容.

您可以在 Word 中录制宏并在 Outlook VBA 项目中使用相同的代码,只需确保设置引用“Microsoft Word 对象库 " 这样 Outlook 就可以识别 Word 使用的对象。

例子

Option Explicit
Public Sub UseWord()
    Dim Ins As Outlook.Inspector
    Dim wDoc As Word.Document
    Dim Word As Word.Application
    Dim Selection As Word.Selection

    Set Ins = Application.ActiveInspector
    Set wDoc = Ins.WordEditor
    Set Word = wDoc.Application
    Set Selection = Word.Selection

    'insert here your macro from word

End Sub

这里有帮助LinkOutlook 2010