如何设置Outlook文件夹的自定义图标? [英] How to set a custom Icon of an Outlook folder?

查看:567
本文介绍了如何设置Outlook文件夹的自定义图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法来设置使用Outlook对象模型Outlook文件夹或子文件夹的自定义图标?


解决方案

由于从展望2010年,您可以使用 MAPIFolder.SetCUstomIcon 如上所述。



最近我有同样的挑战,发现在
更改Outlook文件夹的颜色可能?:






joelandre <子>的 2015年1月12日在下午9时13




  1. 解压文件的 icons.zip 到C:\icons

  2. 定义下面的代码的Visual Basic宏

  3. 根据您的需要文本



    <预类适应功能ColorizeOutlookFolders =郎VBA prettyprint-覆盖> 函数的GetFolder(BYVAL FOLDERPATH作为字符串)作为Outlook.folder
    '返回Outlook文件夹对象基础上的文件夹路径
    '
    昏暗TempFolder作为Outlook.folder
    尺寸FoldersArray为Variant
    暗淡我作为整数

    在错误转到GetFolder_Error

    '中的文件夹路径删除前导斜杠
    如果左(FOLDERPATH,2)=\\然后
    FOLDERPATH =右(FOLDERPATH,莱恩(FOLDERPATH) - 2)
    端如果

    '转换FOLDERPATH数组
    FoldersArray =斯普利特(FOLDERPATH,\)
    将TempFolder = Application.Session.Folders.Item(FoldersArray(0))

    。如果不TempFolder是Nothing然后
    。对于i = 1到UBound函数(FoldersArray,1)
    昏暗的子文件夹Outlook.Folders
    将子文件夹= TempFolder.Folders
    将TempFolder = SubFolders.Item( FoldersArray(I))
    如果TempFolder是Nothing然后
    组的GetFolder =什么
    端如果
    下一步
    端如果
    '返回TempFolder
    设置的GetFolder = TempFolder
    退出功能GetFolder_Error:
    组的GetFolder =什么
    退出功能结束功能子ColorizeOneFolder(FOLDERPATH作为字符串,FolderColour作为字符串)
    昏暗myPic由于IPictureDisp
    昏暗的文件夹Outlook.folder

    将文件夹=的GetFolder(FOLDERPATH)
    将myPic =的LoadPicture(C:\icons\+ FolderColour +。ICO)
    。如果不(文件夹是没有什么)然后
    设置自定义图标文件夹
    folder.SetCustomIcon myPic
    'Debug.Print设置颜色为+ FOLDERPATH +作为 + FolderColour
    结束如果结束子

    子ColorizeFolderAndSubFolders(strFolderPath作为字符串,strFolderColour作为字符串)
    '此过程着色的由strFolderPath给出的foler和所有subfolfers

    尺寸olProjectRootFolder作为Outlook.folder
    将olProjectRootFolder =的GetFolder(strFolderPath)

    尺寸b尺寸olNewFolder我只要$ b $作为Outlook.MAPIFolder
    昏暗olTempFolder作为展望.MAPIFolder
    昏暗strTempFolderPath作为字符串

    '上色文件夹
    呼叫ColorizeOneFolder(strFolderPath,strFolderColour)

    '遍历当前文件夹中的项目。
    对i = olProjectRootFolder.Folders.Count要1步骤-1

    将olTempFolder = olProjectRootFolder.Folders(我)

    strTempFolderPath = olTempFolder.FolderPath

    '打印在VB编辑器的立即窗口
    文件夹路径和名称'Debug.Print sTempFolderPath

    '上色文件夹
    呼叫ColorizeOneFolder(strTempFolderPath,strFolderColour)
    下一

    。对于每个olNewFolder在olProjectRootFolder.Folders
    '递归调用
    'Debug.Print olNewFolder.FolderPath
    呼叫ColorizeFolderAndSubFolders(olNewFolder.FolderPath,strFolderColour)
    下一步

    端子

    子ColorizeOutlookFolders()

    呼叫ColorizeFolderAndSubFolders(\\Personal\Documents\000 -Mgmt-CH\100人民,蓝)
    呼叫ColorizeFolderAndSubFolders(\\Personal\Documents\000-MGMT-CH\200-工程,红)
    呼叫了ColorizeFolderAndSubFolders(\\Personal\Documents\000-MGMT-CH\500的会议,绿色环保)
    呼叫ColorizeFolderAndSubFolders(\\Personal\Documents\\ \\000-MGMT-CH\800产品,洋红)
    呼叫ColorizeFolderAndSubFolders(\\Personal\Documents\000-MGMT-CH\600-部门,灰色 )

    呼叫ColorizeFolderAndSubFolders(\\Mailbox - 丹Wilson\Inbox\Customers,灰色)


    端子


  4. 在对象ThisOutlookSession,定义下列功能:



    <预类=郎VBA prettyprint-覆盖> 私人小组Application_Startup()

    ColorizeOutlookFolders

    端子








在为了不色的子文件夹,您可以用函数
ColorizeOneFolder代替ColorizeFolderAndSubFolders例如



<预类=郎VBA prettyprint-覆盖> 子ColorizeOutlookFolders()

呼叫ColorizeOneFolder(\\Personal\Documents\000-Mgmt- CH\100人民,蓝)
呼叫ColorizeOneFolder(\\Personal\Documents\000-MGMT-CH\200-工程,红)
呼叫ColorizeOneFolder(\\Personal\Documents\000-MGMT-CH\500的会议,绿色环保)
呼叫ColorizeOneFolder(\\Personal\Documents\000- MGMT-CH\800产品,洋红)
呼叫ColorizeOneFolder(\\Personal\Documents\000-MGMT-CH\600-部门,灰色)

呼叫ColorizeOneFolder(\\Mailbox - 丹Wilson\Inbox\Customers,灰色)

端子

在文件夹之间移动子文件夹时,应保留其
颜色只有你重新启动Outlook,直到下一次。



Is there any way to set a custom Icon of an Outlook folder or subfolder using Outlook object model?

解决方案

As from Outlook 2010 you can use MAPIFolder.SetCUstomIcon as described above.

I have had the same challenge recently and found a nice snippet of VBA code at Change Outlook folders colors possible?:

joelandre Jan 12, 2015 at 9:13 PM

  1. Unzip the file icons.zip to C:\icons
  2. Define the code below as Visual Basic Macros
  3. Adapt the function ColorizeOutlookFolders according to your needs 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
    

  4. In the object ThisOutlookSession, define the following function:

    Private Sub Application_Startup()
    
    ColorizeOutlookFolders
    
    End Sub
    

and

In order to NOT color sub-folders, you can use the function ColorizeOneFolder instead of ColorizeFolderAndSubFolders e.g.

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

When you move sub-folders between folders, they should retain their color only until the next time you restart Outlook.

这篇关于如何设置Outlook文件夹的自定义图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆