Outlook SentMailFolder 宏

Outlook SentMailFolder 宏

我正在尝试创建一个宏来对我的已发送项目文件夹运行规则。但总是遇到“对象变量或未设置块变量”星号,我是这方面的新手,所以任何帮助我都非常感谢。

这是另一次失败的尝试

Private Sub Application_Startup() runRulesOnSentMailFolder End Sub

Sub runRulesOnSentMailFolder() Dim st 作为 Outlook.Store Dim myRules 作为 Outlook.Rules Dim rl 作为 Outlook.Rule Dim count 作为整数 Dim ruleList 作为字符串 Dim rulePrefix 作为字符串 Dim ruleFolder 作为 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

子目录结束

相关内容