Outlook 设置VBA以读取个人收件箱

Outlook 设置VBA以读取个人收件箱,outlook,Outlook,尝试将一些VBA代码整合在一起,以便基本上能够从outlook 2007中工具栏上的按钮运行我的规则。以下代码在我的exchange server收件箱上运行规则,当所有内容都移动到我的“个人收件箱”时,该收件箱为空。我只想更改下面的代码以读取我的个人收件箱,而不是exchange邮箱收件箱。我已经在网上搜索过了,但找不到我的答案,因此我的帖子- Sub RunAllInboxRules() Dim st As Outlook.Store Dim myRules As Outlook.Rules

尝试将一些VBA代码整合在一起,以便基本上能够从outlook 2007中工具栏上的按钮运行我的规则。以下代码在我的exchange server收件箱上运行规则,当所有内容都移动到我的“个人收件箱”时,该收件箱为空。我只想更改下面的代码以读取我的个人收件箱,而不是exchange邮箱收件箱。我已经在网上搜索过了,但找不到我的答案,因此我的帖子-

Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next


' get default store (where rules live)
Set st = Application.Session.DefaultStore
' get rules
Set myRules = st.GetRules

' iterate all the rules
For Each rl In myRules
    ' determine if it's an Inbox rule
    If rl.RuleType = olRuleReceive Then
        ' if so, run it
        rl.Execute ShowProgress:=True
        count = count + 1
        ruleList = ruleList & vbCrLf & rl.Name
    End If
Next

' tell the user what you did
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"

Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub

试试这个。我已经在我的机器上测试过了。这将登录到您登录的邮箱并相应地运行规则

Sub RunAllInboxRules()
Dim objOL As Outlook.Application
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
Dim fldInbox As Object
Dim gnspNameSpace As Outlook.NameSpace

'On Error Resume Next

' get default store (where rules live)

'Logs into Outlook session
    Set objOL = Outlook.Application
    Set gnspNameSpace = objOL.GetNamespace("MAPI") 'Outlook Object
   'Logs into the default Mailbox Inbox

'set the store to the mailbox

Set st = gnspNameSpace.GetDefaultFolder(olFolderInbox).Store

' get rules

Set myRules = st.GetRules

' iterate all the rules
For Each rl In myRules
    ' determine if it's an Inbox rule
    If rl.RuleType = olRuleReceive Then
        ' if so, run it
        rl.Execute ShowProgress:=True
        count = count + 1
        ruleList = ruleList & vbCrLf & rl.Name
    End If
Next

' tell the user what you did
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"

Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub