'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 1:[1]
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
Solution 2:[2]
These extra properties must be set on the OLE storage level used by the MSG file - StgCreateDocfileOnILockBytes
/ IPropertySetStorage::Create
/ IPropertySetStorage::WriteMultiple
If using Redemption (I am its author) is an option, it exposes olMsgWithSummary
format (similar to olMsg
and olMsgUnicode
in OOM) that will do what you need. The script below saves the currently selected Outlook message:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set oMsg = Application.ActiveExplorer.Selection(1)
set rMsg = Session.GetRDOObjectFromOutlookObject(oMsg)
rMsg.SaveAs "c:\temp\ExtraProps.msg", 1035 '1035 is olMsgWithSummary
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dayo |
Solution 2 | Dmitry Streblechenko |