2

我需要按名称获取文件夹,而不是按文件夹编号计数。我尝试了各种方法。

Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
'Dim OlFolder As Outlook.MAPIFolder
Dim objFolder As Outlook.Folder
Dim myolItems As Outlook.Items
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
'Set myOlItems = objNS.GetDefaultFolder(37).Folders("Vijay Baswal").Items
'Open the folder
Set objFolder = olApp.Session.GetDefaultFolder("Vijay Baswal")
4

2 回答 2

3

说在收件箱下面是一个名为 Clients 的文件夹,在它下面是一个名为 Vijay Baswal 的文件夹

设置 objFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("Clients").Folders("Vijay Baswal")

OlDefaultFolders 枚举http://msdn.microsoft.com/en-us/library/office/bb208072(v=office.12).aspx

收件箱是 olFolderInbox 或 6。似乎没有 37。

于 2013-10-26T12:14:21.820 回答
2

请参阅下面的 vba 片段以检查如何从特定文件夹中读取邮件

 Dim olApp As Outlook.Application
Dim olNs As Outlook.NameSpace
Dim olFldr As Outlook.MAPIFolder
Dim olItms As Outlook.Items
Dim olMail As Variant
Dim outFolder As Outlook.Folder

 Dim olItem As Outlook.MailItem


Dim i As Long

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.Folders("folder1").Folders("fol2")
Set olItms = olFldr.Items


olItms.Sort "Subject"

i = 1

For Each olItem In olItms
    'If InStr(olMail.Subject, "Criteria") > 0 Then

       Dim szVar As String
      szVar = olItem.Body
        szVar1 = olItem.Subject
        i = i + 1
    'End If
Next olItem

Set olFldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
于 2015-12-15T06:03:54.733 回答