我正在编写一个自动化脚本,该脚本将从一天到达的4封电子邮件收集数据,并在当天结束时发送报告电子邮件,我已经找到了如何附加将要发送的文本文件以及如何搜索特定字符串的电子邮件,告诉我一切是否正常。
但我有一个问题。我把一些代码放到了Subs和Functions中,它停止了工作。 itm.Body在Function CheckSafeSet中不可见,如果IF不合适,那么有什么奇怪的不运行。
请帮忙。如果您有任何不同的建议,请更明智地告诉我
感谢Michal
Public Sub AppendTextFiles(safeset As String)
Open "C:\AppSupport\testfilew.txt" For Append As #1
Print #1, safeset
Close #1
End Sub
Function CheckSafeSet(safeset As String)
MsgBox ("1")
MsgBox (itm.Body)
If itm.Body Like safeset Then
MsgBox ("2")
Call AppendTextFiles("adfsdfasdfsergedgrrt")
Else:
MsgBox ("FAIL")
End If
End Function
Public Sub process_email(itm As Outlook.MailItem)
'Strings - Savegroups
Dim d1000i As String
Dim d1200i As String
Dim l0001i As String
l0001i = "*Savegroup: VNX_UK_NDMP_00:01*"
Dim l2000i As String
Dim lonparch01 As String
'lonparch01 = "*pnwifsvbbup03.r3-core.r3.aig.net:/root_vdm_1/vol_lonparch01_snap 42927:nsrndmp_save: Successfully done*"
lonparch01 = "*NDMP*"
Dim new_msg As MailItem
If itm.Body Like l0001i Then
MsgBox (itm.Body)
Call CheckSafeSet(lonparch01)
Else:
End If
End Sub
答案 0 :(得分:1)
问题是您尚未将itm对象传递给CheckSafeSet函数。你需要将它作为Outlook.MailItem添加到CheckSafeSet函数的签名然后传递itm对象
Public Sub AppendTextFiles(safeset As String)
Open "C:\AppSupport\testfilew.txt" For Append As #1
Print #1, safeset
Close #1
End Sub
Function CheckSafeSet(safeset As String, itm As Outlook.MailItem)
MsgBox ("1")
MsgBox (itm.Body)
If itm.Body Like safeset Then
MsgBox ("2")
Call AppendTextFiles("adfsdfasdfsergedgrrt")
Else
MsgBox ("FAIL")
End If
End Function
Public Sub process_email(itm As Outlook.MailItem)
'Strings - Savegroups
Dim d1000i As String
Dim d1200i As String
Dim l0001i As String
l0001i = "*Savegroup: VNX_UK_NDMP_00:01*"
Dim l2000i As String
Dim lonparch01 As String
'lonparch01 = "*pnwifsvbbup03.r3-core.r3.aig.net:/root_vdm_1/vol_lonparch01_snap 42927:nsrndmp_save: Successfully done*"
lonparch01 = "*NDMP*"
Dim new_msg As MailItem
If itm.Body Like l0001i Then
MsgBox (itm.Body)
Call CheckSafeSet(lonparch01, itm)
Else
End If
End Sub