2015-06-05 113 views
1

我有一個排序腳本在所有的郵件中執行。展望vba腳本停止工作

該帳戶由5臺計算機共享,並且所有人都運行該腳本。

由於某些原因,腳本工作正常,但有一段時間它停止工作,我在腳本中設置了一個調試點,並且該腳本未被執行。該規則不顯示任何錯誤。

Sub sortingP8(Item As Outlook.MailItem) 
    Dim olkAtt As Outlook.Attachment 
    'Check each attachment 
    Dim totalSize As Double 
    Dim containsZip As Boolean 
    Dim wrongExt As Boolean 
    totalSize = 0 
    containsZip = False 
    wrongExt = False 
    somethingWrong = False 
    Set ns = Application.GetNamespace("MAPI") 
    Set nonIngFolder = ns.Folders("[email protected]").Folders("Non-ingestible Items") 
    Set ingFolder = ns.Folders("[email protected]").Folders("Ingestible Items") 
    Set zipFolder = ns.Folders("[email protected]").Folders("ZIP files") 

    For Each olkAtt In Item.Attachments 
     Dim extension As String 
     extension = Right(LCase(olkAtt.FileName), 4) 
     'If the attachment's file name ends with .zip 
     totalSize = totalSize + olkAtt.Size 

     If extension <> ".ppt" And extension <> ".doc" And extension <> ".pdf" And extension <> ".jpg" And extension <> ".zip" Then 
      wrongExt = True 
     End If 
     If extension = ".zip" Then 
      containsZip = True 

     End If 
    Next 
    If (wrongExt = True Or totalSize > 10000000) Then 
     Item.Move nonIngFolder 
     somethingWrong = True 
    End If 
    If (containsZip = True And somethingWrong = False) Then 
     Item.Move zipFolder 
     somethingWrong = True 
    End If 
    If (somethingWrong = False) Then 
     Item.Move ingFolder 
    End If 
    Set olkAtt = Nothing 
End Sub 

任何想法如何發生在每臺計算機?

回答

0

您是否有機會查看Outlook中的信任中心設置? Outlook宏是否允許運行?

嘗試手動運行VBA子版本以防止收到的電子郵件消息,並通過遍歷每行代碼的分步方式調試代碼,並查看會發生什麼情況。

最後,您可能會發現Getting Started with VBA in Outlook 2010文章有幫助。

+0

問題是,有一段時間它工作正常,每次收到郵件時,調試模式顯示(因爲我設置調試點)1-2小時後它不再工作。沒有調試模式,並且附件的郵件不會移動到正確的文件夾 – user3270648

+0

我有宏設置爲「數字簽名宏的通知,所有其他宏禁用」,這可能是一個問題。 在任何情況下,我無法將它們更改爲按鈕顯示禁用。 如果這是問題,第一次如何正常工作? – user3270648

+0

宏可以設置問題嗎?如果這就是爲什麼它第一次運行良好? – user3270648

0

如果將計算機放在一邊,會話斷開超時可能是罪魁禍首。

+0

雖然我有類似的問題 - 你有沒有找到不同的東西? – Dimas