我在 Outlook 中有收入电子邮件和已发布电子邮件的规则。我在网上发现以下例程适用于“收件箱”中的电子邮件,但我无法在需要时使用 GetRootFolder 选择“已发送”项目文件夹。例程如下:
Sub RunRules()
Dim st As Outlook.Store
Dim myRules As Outlook.rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim k As Long
Dim fname As String
Dim currentcount As Integer
Dim prova As String
Dim numero As Integer
Dim prova1 As String
Dim Nrules As Integer
Dim objFolder, objNamespace, objOutlook, objFile
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
objNamespace.Logon "Default Outlook Profile", , False, False
numero = 1
' this is for the SENT Items
fname = "I"
count = 1
k = 1
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
'On Error Resume Next
' get default store (where rules live)
Set st = Application.Session.DefaultStore
Application.Session.DefaultStore.GetRootFolder (olFolderSentMail)
' get rules
Set myRules = st.GetRules
For k = 1 To myRules.count ' might be 0-based, didnt check
On Error Resume Next
Set rl = Nothing
Set rl = myRules(k)
If rl.RuleType = olRuleReceive Then 'determine if it’s an Inbox rule, if so, run it
' I selecto just the rules that are for the sent ITEMS
prova = rl.Name
prova1 = Left(prova, 1)
If prova1 = fname Then
rl.Execute ShowProgress:=True
objFile.WriteLine rl.Name
count = count + 1
prova = ""
prova1 = ""
End If
End If
Next
Set rl(count) = Nothing
Set st = Nothing
Set myRules = Nothing
Set objFolder = Nothing
End Sub