This morning I stumbled across an interesting Outlook question on Quora from a user named Sulong Xu. Sulong Xu asks
How can I view multiple pictures attachments at once in Outlook? Other than one by one, because I want to compare the pictures.
Outlook does not have a built-in means of doing this. It only allows you to view attachments individually. What we need is a solution that presents thumbnail images of all the graphic files attached to a message, something like a digital equivalent to a photographer’s contact sheet. This would allow Sulong Xu to view all the attached images at once. Unlike a contact sheet, the solution would also allow Sulong Xu to click a thumbnail to view the full-sized image. Now, how could we add this capability to Outlook?
The answer, of course, is a macro. Here’s how it will work.
- Get the currently selected or open item.
- For each of the item’s attachments, determine if it is a hidden attachment (images in signatures are hidden attachments and we don’t want these). If it is, then move to the next attachment. Otherwise, move to the next step.
- Is the attachment a graphic? The code determines this by looking for known graphic extensions like .bmp, .jpg, and .png. If the attachment is a graphic, then store its name and save it to disk
- Create a simple HTML page with a thumbnail of each graphic saved in the last step.
- Display the HTML page in the default browser.
The solution below implements this process. Select am item (e.g. message, contact, appointment) and run the macro. A browser window will open with thumbnails of all the attached graphics. Clicking a thumbnail will open the full-sized image in a new browser window.
Outlook 2007 and later.
Instructions and Code.
- Start Outlook
- Press ALT+F11 to open the Visual Basic Editor
- If not already expanded, expand Microsoft Office Outlook Objects
- If not already expanded, expand Modules
- Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
- Copy the code from the code snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Edit the code as needed. I placed comments where things can be changed.
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
Sub ViewContactSheet() 'Edit the next line to change the defualt thumbnail size. Const DEFAULT_THUMBNAIL_PCNT = "10%" Dim olkMsg As Object, _ olkAtt As Outlook.Attachment, _ colNam As New Collection, _ objFSO As Object, _ objFil As Object, _ objShl As Object, _ bolOth As Boolean, _ varNam As Variant, _ strBuf As String Select Case TypeName(Application.ActiveWindow) Case "Explorer" Set olkMsg = Application.ActiveExplorer.Selection(1) Case "Inspector" Set olkMsg = Application.ActiveInspector.CurrentItem Case Else bolOth = True End Select If (Not bolOth) Then Set objFSO = CreateObject("Scripting.FileSystemobject") Set objShl = CreateObject("WScript.Shell") For Each olkAtt In olkMsg.Attachments If Not IsHiddenAttachment(olkAtt) Then Select Case LCase(objFSO.GetExtensionName(olkAtt.FileName)) 'Edit the list of known graphic file types on the next line Case "bmp", "gif", "jpg", "jpeg", "png" olkAtt.SaveAsFile Environ("TEMP") & "\" & olkAtt.FileName colNam.Add olkAtt.FileName End Select End If Next For Each varNam In colNam strBuf = strBuf & "<a href=""file://" & Environ("TEMP") & "\" & varNam & """ target=""_new""><img src=""" & varNam & """ height=""" & DEFAULT_THUMBNAIL_PCNT & """ width=""" & DEFAULT_THUMBNAIL_PCNT & """ /></a><br><br>" Next strBuf = "<html><head></head><body>" & strBuf & "</body></html>" Set objFil = objFSO.CreateTextFile(Environ("TEMP") & "\ContactSheet.html") objFil.Write strBuf objFil.Close objShl.Run Environ("TEMP") & "\ContactSheet.html" End If Set olkMsg = Nothing Set olkAtt = Nothing Set colNam = Nothing Set objFSO = Nothing Set objFil = Nothing Set objShl = Nothing End Sub Public Function IsHiddenAttachment(olkAtt As Outlook.Attachment) As Boolean ' Purpose: Determines if an attachment is a hidden attachment. ' Written: 7/12/2012 ' Author: David Lee ' Outlook: 2007 and later Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E" Dim olkPA As Outlook.PropertyAccessor, varTemp As Variant On Error Resume Next Set olkPA = olkAtt.PropertyAccessor varTemp = olkPA.GetProperty(PR_ATTACH_CONTENT_ID) IsHiddenAttachment = (varTemp <> "") On Error GoTo 0 Set olkPA = Nothing End Function
Click to Run
Running the macro with a single click requires a bit more work. For Outlook 2007 you can add a button to the toolbar. Outlook 2010 uses the ribbon, so for this version we’ll add a button to the Quick Access Toolbar (QAT).
Outlook 2007. Follow these instructions to add toolbar buttons that run the macro.
Outlook 2010. Follow these instructions to add the macro to the QAT.