我希望在使用" subject"的电子邮件时运行Excel宏。被发送到我的收件箱。我在“管理规则”和“管理规则”中设置了运行脚本。 Outlook中的警报。当我收到一封带有"主题"宏没有任何反应。
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
答案 0 :(得分:0)
从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