在 VBA outlook 规则的代码中,如何 use/reference 导致触发的电子邮件

In VBA code for outlook rule, how to use/reference the email which caused the trigger

我已经为 运行 脚本创建了一个规则,用于当电子邮件具有某些 headers 时。 我的脚本试图从电子邮件中获取 excel table 内容并将其保存在本地,以便进一步处理。

以下是我找到并使用的片段: https://social.msdn.microsoft.com/Forums/en-US/22631e7e-53df-47c4-b625-22c9e935f02b/copy-a-table-from-body-of-an-email-to-excel-spreadsheet?forum=outlookdev

当我使用 Application.ActiveExplorer.Item 时有效,也就是在 运行ning 时打开的电子邮件上。

但是,我希望对触发它的电子邮件执行以下操作。我试图遵循 和他们的逻辑 ByRef,但它对我不起作用。

有人可以告诉我如何通过在触发电子邮件中使用下面的 GetInspector.WordEditor 逻辑来获取 table 文本吗?谢谢!

Sub getDailyCollMV(ByRef Item As Outlook.MailItem)
Dim r As Object  'As Word.Range
Dim doc As Object 'As Word.Document
Dim xlApp As Object, wkb As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set wkb = xlApp.Workbooks.Add
xlApp.Visible = False
xlApp.DisplayAlerts = False

Dim wks As Object
Set wks = wkb.Sheets(1)

For Each ItemVal In Application.ActiveExplorer.Item
Set doc = ItemVal.GetInspector.WordEditor
    For x = 1 To doc.tables.Count
     Set r = doc.tables(x)
        r.Range.Copy
       wks.Paste
       wks.Cells(wks.Rows.Count, 1).End(3).Offset(1).Select
    Next
Next

替换行

For Each ItemVal In Application.ActiveExplorer.Item
Set doc = ItemVal.GetInspector.WordEditor

Set doc = Item.GetInspector.WordEditor