Outlook SentMailFolder マクロ

Outlook SentMailFolder マクロ

送信済みアイテム フォルダーでルールを実行するマクロを作成しようとしています。しかし、「オブジェクト変数またはブロック変数が設定されていません」というアスタリスクが表示され続けます。私はこの分野の初心者なので、助けていただければ幸いです。

もう一つの失敗した試み

プライベートサブ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 Dim ruleList 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

終了サブ

関連情報