2012-07-19 4 views
0

소득 전자 메일 및 게시 된 전자 메일에 대한 규칙이 Outlook에 있습니다. 나는 웹에서 'INBOX'에있는 이메일에 대해 다음과 같은 루틴을 발견했지만 GetRootFolder를 사용하여 'SENT'Items 폴더를 선택할 필요가 없습니다. 루틴은 다음매크로를 통해 내 규칙을 실행하십시오. 보낸 편지함 폴더를 선택할 수 없습니다

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 

답변

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