我正在尝试获取与链接到我的 Outlook 帐户的共享邮箱上的类别相关联的项目数。我发现的所有代码仅引用实际的 Outlook 类别,我不确定如何设置项目以查看共享邮箱以对类别进行计数。我相信问题出在下面的粗体代码中,但找不到引用共享邮箱的属性。
我对这段代码做了一些调整以满足我的需求,但它是由 Shirley Zhang 编写的:
Public objDictionary As Object
Public objExcelApp As Excel.Application
Public objExcelWorkbook As Excel.Workbook
Public objExcelWorksheet As Excel.Worksheet
Sub ExportCountofItemsinEachColorCategories()
Dim objCategories As Object
Dim objCategory As Object
Dim objPSTFile As Outlook.Folder
Dim objFolder As Outlook.Folder
Dim strExcelFile As String
'Create a New Excel file
Set objExcelApp = CreateObject("Excel.Application")
Set objExcelWorkbook = objExcelApp.Workbooks.Add
Set objExcelWorksheet = objExcelWorkbook.Sheets("Sheet1")
objExcelWorksheet.Cells(1, 1) = "Color Category"
objExcelWorksheet.Cells(1, 2) = "Count"
'Find all the color categories
Set objDictionary = CreateObject("Scripting.Dictionary")
'I believe the error is here vvv
Set objCategories = Outlook.Application.Session.Categories
For Each objCategory In objCategories
objDictionary.Add objCategory.Name, 0
Next
Set objPSTFile = Outlook.Application.Session.PickFolder
For Each objFolder In objPSTFile.Folders
ProcessFolder objFolder
Next
'Save the new Excel file
objExcelWorksheet.Columns("A:B").AutoFit
strExcelFile = "C:\Users\cdlane\Documents\Color Categories (" & Format(Now, "yyyy-mm-dd_hh-mm-ss") & ").xlsx"
objExcelWorkbook.Close True, strExcelFile
MsgBox "Complete!", vbExclamation
End Sub
答案1
Sub CategoriesByStore()
Dim colStores As Stores
Dim oStore As store
Dim objCategories As Categories
Dim objCategory As Category
Dim i As Long
Set colStores = Session.Stores
' Debug.Print "colStores.count: " & colStores.count
For i = 1 To colStores.count
Set oStore = colStores(i)
Debug.Print "Store " & i & ": " & oStore
If oStore = "store name from immediate window" Then
Set objCategories = oStore.Categories
For Each objCategory In objCategories
Debug.Print objCategory
Next
Exit For
End If
Next
End Sub