有没有办法使用Outlook对象模型设置Outlook文件夹或子文件夹的自定义图标?
答案 0 :(得分:3)
从Outlook 2010开始,您可以使用MAPIFolder.SetCUstomIcon
,如上所述。
我最近遇到了同样的挑战,并找到了一个很好的VBA代码片段 Change Outlook folders colors possible?:
joelandre Jan 12, 2015 at 9:13 PM
- 将文件icons.zip解压缩到C:\ icons
- 将以下代码定义为Visual Basic宏
根据您的需要调整ColorizeOutlookFolders函数Text
Function GetFolder(ByVal FolderPath As String) As Outlook.folder ' Returns an Outlook folder object basing on the folder path ' Dim TempFolder As Outlook.folder Dim FoldersArray As Variant Dim i As Integer On Error GoTo GetFolder_Error 'Remove Leading slashes in the folder path If Left(FolderPath, 2) = "\\" Then FolderPath = Right(FolderPath, Len(FolderPath) - 2) End If 'Convert folderpath to array FoldersArray = Split(FolderPath, "\") Set TempFolder = Application.Session.Folders.Item(FoldersArray(0)) If Not TempFolder Is Nothing Then For i = 1 To UBound(FoldersArray, 1) Dim SubFolders As Outlook.Folders Set SubFolders = TempFolder.Folders Set TempFolder = SubFolders.Item(FoldersArray(i)) If TempFolder Is Nothing Then Set GetFolder = Nothing End If Next End If 'Return the TempFolder Set GetFolder = TempFolder Exit Function GetFolder_Error: Set GetFolder = Nothing Exit Function End Function Sub ColorizeOneFolder(FolderPath As String, FolderColour As String) Dim myPic As IPictureDisp Dim folder As Outlook.folder Set folder = GetFolder(FolderPath) Set myPic = LoadPicture("C:\icons\" + FolderColour + ".ico") If Not (folder Is Nothing) Then ' set a custom icon to the folder folder.SetCustomIcon myPic 'Debug.Print "setting colour to " + FolderPath + " as " + FolderColour End If End Sub Sub ColorizeFolderAndSubFolders(strFolderPath As String, strFolderColour As String) ' this procedure colorizes the foler given by strFolderPath and all subfolfers Dim olProjectRootFolder As Outlook.folder Set olProjectRootFolder = GetFolder(strFolderPath) Dim i As Long Dim olNewFolder As Outlook.MAPIFolder Dim olTempFolder As Outlook.MAPIFolder Dim strTempFolderPath As String ' colorize folder Call ColorizeOneFolder(strFolderPath, strFolderColour) ' Loop through the items in the current folder. For i = olProjectRootFolder.Folders.Count To 1 Step -1 Set olTempFolder = olProjectRootFolder.Folders(i) strTempFolderPath = olTempFolder.FolderPath 'prints the folder path and name in the VB Editor's Immediate window 'Debug.Print sTempFolderPath ' colorize folder Call ColorizeOneFolder(strTempFolderPath, strFolderColour) Next For Each olNewFolder In olProjectRootFolder.Folders ' recursive call 'Debug.Print olNewFolder.FolderPath Call ColorizeFolderAndSubFolders(olNewFolder.FolderPath, strFolderColour) Next End Sub Sub ColorizeOutlookFolders() Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\100-People", "blue") Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\200-Projects","red") Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\500-Meeting", "green") Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\800-Product", "magenta") Call ColorizeFolderAndSubFolders("\\Personal\Documents\000-Mgmt-CH\600-Departments", "grey") Call ColorizeFolderAndSubFolders("\\Mailbox - Dan Wilson\Inbox\Customers", "grey") End Sub
- 醇>
在对象ThisOutlookSession中,定义以下函数:
Private Sub Application_Startup() ColorizeOutlookFolders End Sub
和
为了不对子文件夹着色,您可以使用该功能 ColorizeOneFolder而不是ColorizeFolderAndSubFolders,例如
Sub ColorizeOutlookFolders() Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\100-People", "blue") Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\200-Projects", "red") Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\500-Meeting", "green") Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\800-Product", "magenta") Call ColorizeOneFolder ("\\Personal\Documents\000-Mgmt-CH\600-Departments", "grey") Call ColorizeOneFolder ("\\Mailbox - Dan Wilson\Inbox\Customers", "grey") End Sub
当你在文件夹之间移动子文件夹时,他们应该保留它们 只有在下次重新启动Outlook时才会显示颜色。
答案 1 :(得分:2)
根据我的阅读,很遗憾在Outlook 2007中无法实现这一点。
在Outlook 2010中可以使用MAPIFolder.SetCustomIcon
。有关详细信息,请参阅MSDN:http://msdn.microsoft.com/en-us/library/ff184775.aspx
在以下MSDN网页上切换2010和2007之间的MAPIFolder方法列表,仅显示2010年的SetCustomIcon
方法:http://msdn.microsoft.com/en-us/library/bb645002.aspx