【发布时间】:2020-11-24 16:33:19
【问题描述】:
我使用 Outlook 2019 管理十 (10) 个电子邮件帐户
我更喜欢单行表格视图
目标:所有邮件文件夹中的列均等排列
在所有收件箱和子文件夹上显示具有相同宽度和顺序的列重要性、图标、状态、附件、发件人、主题、日期、大小(期望“发送”文件夹在我想要“到”而不是“来自")。
现有的部分解决方案:
- 我有一个 VBA 脚本(见下文)来读取“参考文件夹”(我在其中手动排列内容)的格式(在
Outlook.Folder.CurrentView.ViewFields中),然后将其应用于当前选定的文件夹 - 适用于列类型、宽度和名称
还有一个问题:
- 这不会影响排序
- 一切都设置好了,但是顺序和配置中的顺序不一样
问题:如何通过 VBA 影响Outlook.Folder.CurrentView.ViewFields 的列顺序?
Sub ApplyReferenceColumnFormatToSelectedFolder()
Dim myNamespace As Outlook.NameSpace
Set myNamespace = Application.GetNamespace("MAPI")
' read ViewFields of reference folder into dictionary
Dim refFolder As Outlook.Folder
Set refFolder = myNamespace.Folders.Item("myaccount@myprovider.someTLD").Folders.Item("Posteingang")
Dim refFields As Dictionary
Set refFields = New Dictionary
Dim thisField As Dictionary
' iterate over all fields and read the relevant config data
' result is in two-dimensional dictionary
I = 1
For Each refField In refFolder.CurrentView.ViewFields
Set thisField = New Dictionary
thisField("Label") = refField.ColumnFormat.Label
thisField("ViewXMLSchemaName") = refField.ViewXMLSchemaName
thisField("Width") = refField.ColumnFormat.Width
thisField("FieldFormat") = refField.ColumnFormat.FieldFormat
Set refFields(I) = thisField
I = I + 1
Next
' now "copy" this config to currently selected folder
Set curFolder = Application.ActiveExplorer.CurrentFolder
Set curView = curFolder.CurrentView
' remove all but one ViewFields
' (ideally, would remove all but there needs to be at least one remaining)
oC = curView.ViewFields.Count
If (oC > 1) Then
For I = oC To 2 Step -1
curView.ViewFields.Remove (I)
Next
End If
curView.Apply
' now, set the desired configuration
With curView
' set single-line table view without preview
.AutoPreview = olAutoPreviewNone
.MultiLine = olAlwaysSingleLine
.ShowFullConversations = True
'.Apply
' iterate over the columns form reference folder
I = 1
For Each refField In refFields
Set thisField = refFields(refField)
' add field
' note: can fail, if field of same type already exists
' then, we can just "resume next" without adding :-)
On Error Resume Next
.ViewFields.Add (thisField("ViewXMLSchemaName"))
.Apply
' finally, set the relevant properties
.ViewFields.Item(I).ColumnFormat.Label = thisField("Label")
.ViewFields.Item(I).ColumnFormat.Width = thisField("Width")
.ViewFields.Item(I).ColumnFormat.FieldFormat = thisField("FieldFormat")
.Apply
I = I + 1
Next
End With
curView.Apply
End Sub
【问题讨论】: