如何在Outlook中收到新邮件后运行Excelmacros?

我想运行一个Excelmacros,当“主题”的电子邮件发送到我的收件箱。 我在Outlook的“pipe理规则和警报”中设置了一个脚本。 当我收到一个邮件与“主题”macros没有发生任何事情。

Sub Test(mail As MailItem) Dim ExApp As Excel.Application On Error Resume Next Set ExApp = GetObject(, "Excel.Application") If Not ExApp Is Nothing Then ExApp.Run "'C:\Users\Desktop\Production v2.7.1.xlsm'!Main_function_Auto" End If End Sub 

当您从Outlook调用Excel子程序时,请确保包含模块名称 –

 Option Explicit Public Sub Example(Item As Outlook.MailItem) Dim xlApp As Excel.Application Dim xlBook As Workbook Set xlApp = New Excel.Application Set xlBook = xlApp.Workbooks.Open(Environ( _ "USERPROFILE") & "\Desktop\Production.xlsm") xlApp.Visible = True ' // Run Macro in file xlBook.Application.Run "Module1.Main_function_Auto" Set xlApp = Nothing Set xlBook = Nothing End Sub