如果我收到主题行的电子邮件,我可以打开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
1 回答
看看你的
If
构造...适当的缩进将有助于可视化真正发生的事情......"Run Dashboard"
If
运行 inside "Run CIRM"仪表板“If
...所以你永远不会遇到这种情况(除非收到主题为”运行CIRM仪表板然后运行仪表板“的邮件或者收到了喜欢的邮件) .您可能希望用
Else If
替换第二个If
以使其达到相同的水平