0

我在 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
4

1 回答 1

0

对不起,我之前没有注意到你的问题。

我没有试过你的代码。相反,我展示了我的一个例程的摘录,该例程将选定的属性移动到已发送邮件文件夹中每个邮件项目的变量中。

希望这可以帮助。

Dim FolderTgt As MAPIFolder
Dim HtmlBody As String
Dim InxItemCrnt As Long
Dim ReceivedTime As Date
Dim SenderEmailAddress As String
Dim SenderName As String
Dim Subject As String
Dim TextBody As String
Dim FolderTgt As MAPIFolder

Set FolderTgt = CreateObject("Outlook.Application"). _
                GetNamespace("MAPI").GetDefaultFolder(olFolderSentMail)

For InxItemCrnt = FolderTgt.Items.Count To 1 Step -1
  With FolderTgt.Items.Item(InxItemCrnt)
    If .Class = olMail Then
      ' Save selected data to variables
      ReceivedTime = .ReceivedTime
      Subject = .Subject
      SenderName = .SenderName
      SenderEmailAddress = .SenderEmailAddress
      TextBody = .Body
      HtmlBody = .HtmlBody
    End If
  End With
Next
于 2012-08-20T18:53:24.340 回答