2012-06-22 61 views
1

我需要按名稱獲取文件夾,而不是按文件夾數量計數。我嘗試了各種方法。按名稱引用文件夾

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") 
+0

我寫了一篇關於在Outlook中訪問響應前面一個問題開始的文件夾信息的詳細教程。請參閱http://stackoverflow.com/a/8699250/973283。 –

+0

該文件夾的完整路徑是什麼? – JimmyPena

回答

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