将VBA设置为读取个人收件箱 [英] Setting VBA to read personal inbox

查看:67
本文介绍了将VBA设置为读取个人收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图将一些VBA代码集中在一起,以便基本上能够从Outlook 2007中工具栏上的按钮运行我的规则.以下代码在我的交换服务器收件箱中运行规则,当所有内容移至我的个人"时,该规则为空收件箱".我只想更改下面的代码以读取我的个人收件箱,而不是我的交换邮箱收件箱.在网上搜索过,找不到我的答案,因此也找不到我的帖子-

trying to get some VBA code together to basically be able to run my rules from a button on my toolbar within outlook 2007. The following code runs the rules on my exchange server inbox, which is empty as everything moves to my "Personal Inbox". I just want to change the code below to read my personal inbox and not my exchange mailbox inbox. Have searched on the web and cant find my answer and hence my post -

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

推荐答案

尝试一下.我已经在机器上进行了测试.这将登录到您登录的邮箱并相应地运行规则

Try this. I have tested on my machine. This logs into the mailbox you are logged onto and runs the rules accordingly

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

这篇关于将VBA设置为读取个人收件箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆