我從幾年前的某人的博客得到了這一點的代碼。它基本上遍歷所有的Outlook郵件規則,並執行它們(方便地組織您的收件箱!)。我最近升級到Outlook 2010從2007年現在,我得到一個非常奇怪的錯誤,說明Outlook 2010宏引發VBA錯誤'For循環未初始化'
Run-time error '92':
For loop not initialized
然而,在調試這個,它總是會通過8次(出20-25)上運行,那麼它扔這個錯誤。
這裏是有問題的代碼:
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'get default store (where rules live) & get rules
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
'iterate all the rules
For Each rl In myRules
If rl.RuleType = olRuleReceive Then 'determine if it’s an Inbox rule, if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
Next
'tell the user what you did
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
編輯:
每週杰倫裏格斯的評論,清除塊整個仍然導致錯誤。
由於它總是隻運行8次,第9條規則還有什麼特別之處嗎? – Justin 2011-04-05 15:25:54