我是VBA进阶级别的新手。我可以管理基本的,但是这是更高级的
共享邮箱名称:trvx-prog.obs@orange.com
请参考以下屏幕截图
从此共享邮箱,我需要访问:
但是我无法访问第二个文件夹和子文件夹
Option Explicit
Sub EmailStatsV3()
Dim Item As Object
Dim varOutput() As Variant
Dim lngcount As Long
Dim xlApp As Excel.Application
Dim xlSht As Excel.Worksheet
Dim ShareInbox As Outlook.MAPIFolder
Dim olNs As Outlook.NameSpace
Dim olRecip As Outlook.Recipient
Dim SubFolder As Object
Set olNs = Application.GetNamespace("MAPI")
Set olRecip = olNs.CreateRecipient("trvx-prog.obs@orange.com") '// Owner's Name or email address
Set ShareInbox = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox)
Set SubFolder = ShareInbox.Folders("P_Wardah")
ReDim varOutput(1 To SubFolder.Items.Count, 1 To 4)
For Each Item In SubFolder.Items
If TypeName(Item) = "MailItem" Then
lngcount = lngcount + 1
varOutput(lngcount, 1) = Item.ReceivedTime 'stats on when received
varOutput(lngcount, 2) = Item.Subject 'to split out prefix
varOutput(lngcount, 3) = Item.Sender
varOutput(lngcount, 4) = SubFolder.Name
End If
Next
'Creates a blank workbook in excel
Set xlApp = New Excel.Application
Set xlSht = xlApp.Workbooks.Add.Sheets(1)
xlSht.Range("A1").Resize(UBound(varOutput, 1), _
UBound(varOutput, 2)).Value = varOutput
xlApp.Visible = True
End Sub
答案 0 :(得分:0)
这不是一个完整的答案-只是一种帮助您前进的帮助
您还需要循环遍历SubFolder的所有子文件夹 例如
For Each xFldr In SubFolder.Folders
' Recursive Call to process xFldr
Next
因此,您的文件夹处理例程必须位于其自身的Sub中,然后自己调用(递归调用)