none
Is it possible to put the Windows 7 file system viewer on a VBA userform? RRS feed

  • Question

  • Word 2013, Windows 7

    I have a need to preview PDF files and saved emails from my Word macro.

    Thank-you.

    Thursday, June 11, 2015 5:57 PM

Answers

  • Hi Julie,

    I think it should be possible, you are looking for the PreviewHandler object. There's a .NET example here: http://www.codeproject.com/Articles/533948/NET-Shell-Extensions-Shell-Preview-Handlers.

    However, if you are specifically only looking to preview PDF and Emails then you should be able to get away with displaying a different ActiveX control depending on whether or not you want to display a PDF or an email.

    You could just use a 3rd party ActiveX control for previewing the PDF, some are mentioned on this thread here: http://stackoverflow.com/questions/9336184/pdf-thumbnails-and-preview-in-microsoft-access.

    As for the email, it will either be plain text or HTML so just grab the email body and display it in a browser control.

    I'm currently looking into getting the preview handler working on a .NET project at the moment so I can preview word documents on a form, if I come up with anything that easily ports to VB I will post back and let you know! :)

    • Marked as answer by JW2030 Tuesday, July 21, 2015 2:38 PM
    Friday, June 12, 2015 3:37 PM

All replies

  • Hi Julie

    You've provided such wonderful help, I wish I had a clearly positive answer for you :-) I'm not familiar with a built-in viewer of this nature and don't turn up anything from Microsoft in a quick Google search...

    So I'm only able to provide some basic information that you may be able to use to answer your question, yourself:

    Word VBA UserForms support COM ActiveX controls. If this viewer is available as a COM ActiveX control, then it should theoretically be possible.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, June 12, 2015 2:36 PM
    Moderator
  • Hi Julie,

    I think it should be possible, you are looking for the PreviewHandler object. There's a .NET example here: http://www.codeproject.com/Articles/533948/NET-Shell-Extensions-Shell-Preview-Handlers.

    However, if you are specifically only looking to preview PDF and Emails then you should be able to get away with displaying a different ActiveX control depending on whether or not you want to display a PDF or an email.

    You could just use a 3rd party ActiveX control for previewing the PDF, some are mentioned on this thread here: http://stackoverflow.com/questions/9336184/pdf-thumbnails-and-preview-in-microsoft-access.

    As for the email, it will either be plain text or HTML so just grab the email body and display it in a browser control.

    I'm currently looking into getting the preview handler working on a .NET project at the moment so I can preview word documents on a form, if I come up with anything that easily ports to VB I will post back and let you know! :)

    • Marked as answer by JW2030 Tuesday, July 21, 2015 2:38 PM
    Friday, June 12, 2015 3:37 PM
  • Thank you Cindy. I'll start "hunting" for that elusive Active X control that fits the need.
    Friday, June 12, 2015 4:16 PM
  • Thank you Mark. I'll follow those helpful links and try to get lift-off. Unfortunately using a 3rd party control may stop the show but I will check that out anway.  The installation needs to be simple.  The emails are in .msg format.  Re the browser control, I have a few macros now that view Word documents and PDF via web browser control (converting the Word document to HTML first of course) and find that for systems where Adobe is integrated with Filesite document management, I cannot display the PDFs in the browser - that doesn't make Filesite happy and the result is the computer hangs to the point where a reboot is required.  Hence, the PDF view option has been turned off for those installs so I'm looking for an alternative that doesn't require use of the Filesite API.  The email view is required to work around the problem that saving when saving messages to the file system as .msg files, it does not appear to be possible to populate the extended file attributes.  Hence, users cannot sort effectively in the Windows file system. I was thinking that if I chose a file naming convention for the emails that allow me to parse the info:  "date received ,, from xxx ,, to yyyy, re zzzzzz ,, 2 attachments" then I could let the user browse the emails from a VBA form with option to sort different ways. That requires a preview that is as comfortable to use as is the case with the Windows 7 file system preview which is what spawned my question.

    I sense I will lose this battle, unfortunately but hopefully your links will reveal some clues. Many thanks! JW

    Friday, June 12, 2015 4:26 PM