
Estou tentando criar uma macro para executar uma regra na minha pasta de itens enviados. Mas continue encontrando asteriscos "Variável de objeto ou Com variável de bloco não definida". Sou um novato nisso, então qualquer ajuda será apreciada.
Aqui está outra tentativa fracassada
Sub privado 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
' itera todas as regras para cada rl em myRules ' determina se é uma regra de caixa de entrada e o prefixo do nome da regra corresponde 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
Finalizar sub