如果我收到包含主题行的电子邮件,我可以打开Excel文件:运行CIRM信息中心。
当我收到主题行的电子邮件:“运行仪表板”时,Excel文件无法打开。没有错误。
我需要根据Outlook主题行打开更多文件。
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNameSpace As Outlook.NameSpace
Dim Folder As Outlook.MAPIFolder
Set olNameSpace = Application.GetNamespace("MAPI")
Set Folder = olNameSpace.GetDefaultFolder(olFolderInbox)
Set Items = Folder.Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
If InStr(Item.Subject, "Run CIRM Dashboard") Then
Call CIRMDashboard
If InStr(Item.Subject, "Run Dashboard") Then
Call PendingForRefund
End If
End If
End If
End Sub
Public Function CIRMDashboard()
Dim xlapp As Object
Dim sourceWB
Dim sourceWS
Set xlapp = CreateObject("Excel.Application")
With xlapp
.Visible = True
.EnableEvents = True
End With
strFile = "C:\Users\Dharmendra\Desktop\CIRM Dashboard Auto_Runner.xlsm" '\\ my fist file path
Set sourceWB = xlapp.Workbooks.Open(strFile) ', , False, , , , , , , True)
End Function
Public Function PendingForRefund()
Dim xlapp As Object
Dim sourceWB
Dim sourceWS
Set xlapp = CreateObject("Excel.Application")
With xlapp
.Visible = True
.EnableEvents = True
End With
strFile = "C:\Users\Dharmendra\Desktop\CRM Dashboard Auto_Runner.xlsm" ' \\my second file path
Set sourceWB = xlapp.Workbooks.Open(strFile) ', , False, , , , , , , True)
End Function
答案 0 :(得分:0)
看看你的If
构造......正确的缩进将有助于可视化真正发生的事情......
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
If InStr(Item.Subject, "Run CIRM Dashboard") Then
Call CIRMDashboard
If InStr(Item.Subject, "Run Dashboard") Then
Call PendingForRefund
End If
End If
End If
End Sub
"运行仪表板" 您可能希望将第二个If
在里面运行"运行CIRM"控制板" If
...所以你永远不会遇到这种情况(除非主题为#34; 的邮件运行CIRM仪表板,然后运行仪表板&#34;或收到喜欢的邮件。< / p>
If
替换为Else If
,以使其达到同一水平