PDA

View Full Version : [SOLVED:] Show Word Document to a textbox on a userform



cjmitton
07-27-2018, 03:16 AM
I'm using Word 2016 (32bit) and want to display a selected word document (.docx) in a text box on a userform to 'preview' the contents of that document before they select it. It will then insert in to the current active document the selected document.

From previous macro's I have created I can select a folder and display its content in a listbox (filtered to .docx only). I want to use this so they can see whats selected before inserting it in to the document. I don't want to open a new word instance and understand that the 'formatting' of the word document will not come through on the 'preview' its more for a reminder of content to assist with selection.

So I need assistance with the code to show a word document in a text box and if possible limit the number of characters to 500 (for example) just in case there are some massive documents to be displayed. I've done a far amount of googling and I'm either using the wrong terminology (which is highly probable) or this is not done in VBA that often!

Thanks.

gmayor
07-27-2018, 04:30 AM
https://support.microsoft.com/en-us/help/243058/how-to-use-the-webbrowser-control-to-open-an-office-document may help get you started, though this is not something I have tried personally. You can add a webbrowser object to your userform and you should in theory be able to preview the document in that object. At least you will know what to search for :think:

cjmitton
07-27-2018, 04:41 AM
Thanks, that will get me started. I've taken a look and the example is Visual basic not VBA and was hoping not to go that route as I've not had much luck with creating plug-ins / add-ins for Word. If that is the case I will have to acquire the skills!!!

cjmitton
07-30-2018, 02:55 AM
I've done a bit more browsing and found the following article:
https://rtmccormick.com/2015/11/23/ms-word-document-text-to-string-with-vba/

Thanks to this I've incorporated the function in to my macro and it now does the preview are I require.