我有一个电子邮件帐户" Fred.Smith@domain.co.uk" (正在组建的域名)。
Outlook显示名为&#34的存档;档案 - Fred.Smith@domain.co.uk" Outlook会在一段时间后自动移动电子邮件。
当前代码:
Set olRecip = olNS.CreateRecipient("Archive - Fred.Smith@domain.co.uk")
olRecip.Resolve
Set olFolder = olNS.GetSharedDefaultFolder(olRecip, olFolderInbox)
这将打开主收件箱。如何选择存档文件夹?
答案 0 :(得分:3)
“存档”文件夹通常位于根级别-类似于收件箱 在这种情况下:
Sub ArchiveItems()
' Moves each of the selected items on the screen to an Archive folder.
Dim olApp As New Outlook.Application
Dim olExp As Outlook.Explorer
Dim olSel As Outlook.Selection
Dim olNameSpace As Outlook.NameSpace
Dim olArchive As Outlook.Folder
Dim intItem As Integer
Set olExp = olApp.ActiveExplorer
Set olSel = olExp.Selection
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olArchive = olNameSpace.Folders("myMail@mail.com").Folders("Archive")
For intItem = 1 To olSel.Count
olSel.Item(intItem).Move olArchive
Next intItem
End Sub
要获取收件箱,您可以使用默认访问权限:
Dim olInbox As Outlook.Folder
Set olInbox = olNameSpace.GetDefaultFolder(olFolderInbox)
注意-这将为您提供默认的“收件箱”文件夹,如果Outlook中有几个帐户,则应确认它确实是您想要的文件夹-或使用特定于邮件的方法,例如上述
中的“存档”文件夹用于调试-如果要检查所有可用的子文件夹
For i = 1 To olInbox.Folders.Count
Debug.Print olInbox.Folders(i).Name
Next i
答案 1 :(得分:0)
应
Dim ARCHIVE_FOLDER As Outlook.MAPIFolder
Set ARCHIVE_FOLDER = olNs.Folders("Archive - Fred.Smith@domain.co.uk")
完整示例
Option Explicit
Public Sub Example()
Dim olNs As Outlook.NameSpace
Dim ARCHIVE_FOLDER As Outlook.MAPIFolder
Dim Items As Outlook.Items
Dim i As Long
Set olNs = Application.Session
Dim ARCHIVE_FOLDER As Outlook.MAPIFolder
Set ARCHIVE_FOLDER = olNs.Folders("Archive - Fred.Smith@domain.co.uk") _
.Folders("Inbox")
Debug.Print ARCHIVE_FOLDER.Name
Debug.Print ARCHIVE_FOLDER.FolderPath
Debug.Print ARCHIVE_FOLDER.Store.DisplayName
ARCHIVE_FOLDER.Display
Set Items = ARCHIVE_FOLDER.Items
For i = Items.Count To 1 Step -1
DoEvents
Debug.Print Items(i).Subject
Next
End Sub