Я получил этот фрагмент кода из чьего-то блога много лет назад. Он в основном перебирает все почтовые правила Outlook и выполняет их (удобно для организации вашего почтового ящика!). Я недавно обновился до Outlook 2010 с 2007 года. Теперь я получаю очень странную ошибку с сообщением
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
Изменить:
Согласно комментарию Джея Риггса, очистка всего блока for по-прежнему приводит к ошибке.