本文介绍了更改Outlook收件箱VBA代码正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个VBA脚本,它目前仅在Outlook中打开的第一个收件箱中运行.

I wrote a VBA script, and it currently only operates on the first inbox open in outlook.

如何指定要在哪个收件箱上运行?即另一个帐户的收件箱.

How do I specify which Inbox it operates on? ie, the Inbox of another account.

我想在这里某处-

Sub MoveAgedMail()

Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Dim strDestFolder As String

推荐答案

假设您正在谈论共享收件箱

Assuming your talking about shared Inbox

VBA示例代码为

Option Explicit
Sub OpenShareInbox()
    Dim olNameSpace As Outlook.NameSpace
    Dim olRec As Outlook.Recipient
    Dim olFolder As Outlook.Folder

    Set olNameSpace = Application.GetNamespace("MAPI")
    Set olRec = olNameSpace.CreateRecipient("[email protected]") '// Owner's email address
    Set olFolder = olNameSpace.GetSharedDefaultFolder(olRec, olFolderInbox)

    MsgBox olRec.Name '// Owner Name

    olFolder.Display '// Open Inbox
End Sub

这是另一个示例-打开立即窗口并打印主题行

Here is another Example - Open your immediate window and print Subject line

Option Explicit
Sub OpenShareInbox()
    Dim olNameSpace As Outlook.NameSpace
    Dim olRec As Outlook.Recipient
    Dim olFolder As Outlook.Folder

    Dim olItem As Outlook.MailItem

    Set olNameSpace = Application.GetNamespace("MAPI")
    Set olRec = olNameSpace.CreateRecipient("[email protected]") '// Owner's email address
    Set olFolder = olNameSpace.GetSharedDefaultFolder(olRec, olFolderInbox) '// Inbox


    For Each olItem In olFolder.Items
        Debug.Print olItem.Subject
    Next

End Sub

或转发主题为报告"的邮件项目

Or Forward Mail Item with Subject line "Report"

For Each olItem In olFolder.Items
    If olFolder.DefaultItemType = olMailItem Then
        If olItem.Class = olMail Then
            If olItem.Subject = "Report" Then
                Set olItem = olItem.Forward
                olItem.Subject = "APPENDED SUBJECT - " + olItem.Subject + ""
                olItem.Recipients.Add "Om3r <[email protected]>"
                olItem.Display
    '            olItem.Send
            End If
        End If
    End If
Next

请参见NameSpace.GetSharedDefaultFolder MSDN上的方法(Outlook)

这篇关于更改Outlook收件箱VBA代码正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:22