2015-06-12 89 views
1

我正在寫一個自動化腳本,它將收集來自一天中到達的4封電子郵件的數據並在當天結束時發送報告電子郵件,我已經計算出如何追加將發送的文本文件以及如何搜索發送特定字符串的電子郵件,告訴我一切是否正常。函數沒有獲取變量值?

但我有一個問題。我將一些代碼放入Subs和Functions中,並停止工作。 itm.Body在函數CheckSafeSet中是不可見的,而且如果IF不是真的,則不會運行。

請幫忙。如果您有任何建議,以採取不同的方式,更智能更簡單的請告訴我

感謝米哈爾

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 
+1

於是開始服用碼出的職能和潛艇逐一直到它的作品。然後你知道哪種方法是錯誤的......你是否嘗試過測試? – Adam

+0

您需要將itm傳遞給CheckSafeSet函數,並在您的else子句中刪除: – Sorceri

+0

那麼_AppendTextFiles_函數現在不是問題。問題出在_CheckSafeSet_函數中。我可以從中取出代碼,但實際上我需要它。如果我要取出代碼,它將起作用,但我會退後一步。謝謝 – Michal

回答

1

的問題是,你有沒有通過ITM對象到CheckSafeSet功能。您需要添加ITM作爲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