
我正在嘗試建立一個巨集來在我的已傳送專案資料夾上運行規則。但繼續遇到“物件變數或未設定區塊變數”星號我是這方面的新手,因此感謝任何幫助。
這是另一個失敗的嘗試
Private Sub Application_Startup() runRulesOnSentMailFolder End Sub
Sub runRulesOnSentMailFolder() Dim st As Outlook.Store Dim myRules As Outlook.Rules Dim rl As Outlook.Rule Dim count As Integer DimruleList As String Dim RulePrefix As String Dim RuleFolder As Long
'
Dim outlookApp As Outlook.Application
Dim objNS As NameSpace
ruleFolder = olFolderSentMail
rulePrefix = "SENT_Mail_"
Set objNS = Application.GetNamespace("MAPI")
Set objSentmailfolder = objNS.GetDefaultFolder(ruleFolder)
' get default store (where rules live)
Set st = Application.Session.DefaultStore
' get rules
Set myRules = st.GetRules
' 迭代所有規則 For Each rl In myRules ' 確定它是否是收件匣規則且規則名稱前綴匹配 If rl.RuleType = olRuleReceive And Left(rl.Name, Len(rulePrefix)) = RulePrefix then
' if so, run it
rl.Execute ShowProgress:=True, Folder:=objSentmailfolder
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
****Next****
' tell the user what you did
ruleList = "These rules were executed against the folder: " & objSentmailfolder.Name & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: runRulesOnSentMailFolder"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
Set objSentmailfolder = Nothing
Set objNS = Nothing
結束子