Search code examples
vbaoutlook

Manipulating the item details of an outlook msg file in Windows Explorer using VBA


I have mashed up a VBA script from various web sources to save selected Outlook 2013 mailitems as *.msg files on the filesystem. This works well but I want to add things to the item properties shown in Windows Explorer (Windows 7).

A web search has thrown up confusing info as most seem to assume I want to change CustomProperties or BuiltinProperties but after a lot of time, it appears that what the DSOfile dll does for some other MS Office files is what I need.

In summary, I can select and run a macro to rename and save mail items to the file system as msg files. I am looking for a way to have those items on the file system show additional information when viewed in Windows Explorer. That is, additional columns showing some info beyond the default explorer view.

This information is only relevant within Windows Explorer to allow sorting etc. I cannot involve a separate database etc. I also need to do this within the VBA environment and do not have access to Visio etc.

As an example, Windows Explorer can show "Sender address" and "Sender name" columns. I want to populate these from within VBA for Outlook 2013 msg files.

Is this possible and how can it be done if so?


Solution

  • This function works for my purposes.

    Not exactly the cleanest option but good enough as I can sort items in Explorer on specific columns.

    Function setFileProps(filePath As String)
        Dim objFile As Object
    
        Set objFile = CreateObject("DSOFile.OleDocumentProperties")
        objFile.Open(filePath)
        ' Use "Authors" column to hold Sender's Name
        objFile.SummaryProperties.Author = mItem.SenderName
        ' Use "Comments" column to hold Sender's email address 
        objFile.SummaryProperties.Comments = mItem.SenderEmailAddress
        objFile.save
    
        set objFile = Nothing
    
    End Function
    

    mItem is a mailItem from the main sub and this function is called from there after the mailitem is saved.

    I have then set the target folder in Windows Explorer to show the Author and Comments columns.

    Perhaps there are "cleaner" solutions