我该如何编写宏来将所有文件夹属性设置为“查看所有项目”?我有数百个文件夹和子文件夹,需要将文件夹设置为查看所有项目,但我不知道如何编写宏。最后我决定我需要一些帮助。这应该是 Outlook 中的设置,类似于默认存档设置。
答案1
你要求教你写宏可能太笼统了。所以这里是关于如何展开所有文件夹的答案。
http://www.msoutlook.info/question/595 和
http://vboffice.net/sample.html?lang=en&mnu=2&smp=57&cmd=showitem
您可以决定在需要时展开所有文件夹,而不一定在启动时展开。
“此示例在启动时会打开所有树,并且它是一个奇观...
过程“ExpandAllFolders”中有一个变量“ExpandDefaultStoreOnly”。当前值为 (True) 时,只有个人文件夹会展开。如果要展开所有可用邮箱(档案、Exchange),请将变量设置为 False。”
http://vboffice.net/sample.html?lang=en&mnu=2&smp=57&cmd=showitem
Private Sub Application_Startup()
ExpandAllFolders
End Sub
Private Sub ExpandAllFolders()
On Error Resume Next
Dim Ns As Outlook.NameSpace
Dim Folders As Outlook.Folders
Dim CurrF As Outlook.MAPIFolder
Dim F As Outlook.MAPIFolder
Dim ExpandDefaultStoreOnly As Boolean
ExpandDefaultStoreOnly = True
Set Ns = Application.GetNamespace("Mapi")
Set CurrF = Application.ActiveExplorer.CurrentFolder
If ExpandDefaultStoreOnly = True Then
Set F = Ns.GetDefaultFolder(olFolderInbox)
Set F = F.Parent
Set Folders = F.Folders
LoopFolders Folders, True
Else
LoopFolders Ns.Folders, True
End If
DoEvents
Set Application.ActiveExplorer.CurrentFolder = CurrF
End Sub
Private Sub LoopFolders(Folders As Outlook.Folders, _
ByVal bRecursive As Boolean)
Dim F As Outlook.MAPIFolder
For Each F In Folders
Set Application.ActiveExplorer.CurrentFolder = F
DoEvents
If bRecursive Then
If F.Folders.Count Then
LoopFolders F.Folders, bRecursive
End If
End If
Next
End Sub
答案2
以下脚本将设置您的收件箱在里面默认商店显示总项目数:
Private Sub ShowTotalCount(Folders As Folders)
For Each Folder In Folders
Folder.ShowItemCount = olShowTotalItemCount
ShowTotalCount Folder.Folders
Next
End Sub
Sub ShowTotalCountAll()
ShowTotalCount Session.DefaultStore.GetDefaultFolder(olFolderInbox).Folders
End Sub
只需粘贴到此 Outlook 会话在 Outlook VBA 中(按 ALT+F11 打开它)。之后运行显示全部总数按 F5 键。