none
Creating a preview window in a user form RRS feed

  • Question

  • Hi

    I want to create a preview window of the active document in a user form, apply changes from the user form (for example lets say inserting images) to the preview window but not apply the changes to the document until the user clicks ok in the user form.

    Any help on this would be much appreciated, thanks

    Thursday, January 10, 2013 10:32 PM

Answers

  • Custom Task Pane: This would require a COM add-in (VSTO) - Custom Task Panes aren't available to VBA. But that might not be such a bad thing, if you feel up to the challenge because it would also be the simplest way to implement Word Open XML.

    Word Open XML file format: This would depend a bit on exactly how things should function... One possibility would be to manipulate a file not being displayed to the user, then opening that to show the result of his choices. That would give you the option of having the previous version(s) as files that you could revert to as a single "Undo" step.

    (Remember, Word's undo can involve quite a few steps, although if you're targeting Word 2010 or later it is possible to "bundle" multiple actions into a single Undo step using Application.UndoRecord.)

    The other possibility would be to construct the desired Word Open XML in the "flat package" format and insert that into the document (Range.InsertXML), although I'd expect that to be extremely tricky if so many graphics are involved.

    The Open XML SDK would make using Word Open XML fairly easy, but is only available in the .NET Framework environment. It would probably be possible to create a COM DLL that you could call from VBA, if you really wanted to use the approach from VBA.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by tfitzhardinge Friday, January 18, 2013 6:56 AM
    Wednesday, January 16, 2013 4:13 PM
    Moderator

All replies

  • I think this is going to be next to impossible to achieve for a VBA user form.

    The only way I know to preview a Word document is given in an FAQ at the top of the forum:
      http://social.msdn.microsoft.com/Forums/en/worddev/thread/bd249f1c-3425-49c5-8839-58cbb6b1e5a2

    This "converts" the content to HTML and displays it in a WebBrowser control in a Visual Studio .NET form. Theoretically, the same could work for a VBA form IF you can find a WebBrowser control that will run. That's all fine and good, but it's not possible for the user to edit the result.

    Theoretically, it would also be possible to convert the Word document to RTF and open it in a control that supports RTF editing, but again, I don't know of any such thing for VBA user forms.

    The only "container" I know of which can display a Word document and allow editing in its native format is Word, itself. Perhaps the solution would be to make a copy of the document for the user to edit in-place and only overwrite the original when the user says it's OK...


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, January 11, 2013 7:07 AM
    Moderator
  • Thanks, I was thinking that it was another idea in the too hard basket

    So essentially you create a copy of the document and add a window of the the copy to place in the user form

    Would that mean the the user now sees a 2nd document open just to create this preview window. Is there a way to hide this so that the user does not see or notice that a 2nd document is not open?

    Sunday, January 13, 2013 4:49 AM
  • <<So essentially you create a copy of the document and add a window of the the copy to place in the user form>>

    No.

    I don't thinkit's possible for you to provide anything for your user in your user form in the way of a preview that can be edited.

    You don't explain WHY you want to do this, so it's difficult to discuss possibilities. The only logic I can see for what you want to do is that you don't want to take the chance of damaging the original in some way. That's why I said to make a copy. But the user will still need to work in the Word application, not in your form.


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, January 13, 2013 7:18 AM
    Moderator
  • Sorry I should have explained what I am doing.

    I am creating a table wizard that inserts pictures unlimited amount of pictures into a table with some formatting. Depending on the amount of pictures that the user selects from the file dialog box is the amount of rows. I then when to be able to give the user the ability change the order of the photos that appear in the table. To add some user friendly function I wanted to add in a preview function so the user could see what this table looks like before inserting the table into the document. This preview function would show the full page of what the document would look like with the new table one page at a time. There would be scroll buttons to go to the first, last, next and previous page or simply type in a page number.

    Let me know if any of the above is not clear or you require further explanation. Thanks again for your help.

    Sunday, January 13, 2013 8:03 AM
  • What I'd probably consider, if someone asked me to provide something along these lines, would be a Custom Task Pane in the Word application and manipulate a document opened in the Word application (not necessarily the original file if the purpose is to preview a table of pictures).

    I'd probably consider leveraging the Word Open XML file format, rather than using the object model, in order to improve processing speed.

    If it had to be VBA it could probably work using a form "over/beside" the document window, but that wouldn't be my first choice...


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, January 15, 2013 8:34 AM
    Moderator
  • Thanks Cindy

    What do you mean by "leveraging the Word Open XML file format, rather than using the object model"

    I like the idea of the custom task pane shown on the edge of the document. Word has undo/redo functionality so I do not need to create a preview functionality.

    Thanks

    Wednesday, January 16, 2013 12:12 AM
  • Custom Task Pane: This would require a COM add-in (VSTO) - Custom Task Panes aren't available to VBA. But that might not be such a bad thing, if you feel up to the challenge because it would also be the simplest way to implement Word Open XML.

    Word Open XML file format: This would depend a bit on exactly how things should function... One possibility would be to manipulate a file not being displayed to the user, then opening that to show the result of his choices. That would give you the option of having the previous version(s) as files that you could revert to as a single "Undo" step.

    (Remember, Word's undo can involve quite a few steps, although if you're targeting Word 2010 or later it is possible to "bundle" multiple actions into a single Undo step using Application.UndoRecord.)

    The other possibility would be to construct the desired Word Open XML in the "flat package" format and insert that into the document (Range.InsertXML), although I'd expect that to be extremely tricky if so many graphics are involved.

    The Open XML SDK would make using Word Open XML fairly easy, but is only available in the .NET Framework environment. It would probably be possible to create a COM DLL that you could call from VBA, if you really wanted to use the approach from VBA.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by tfitzhardinge Friday, January 18, 2013 6:56 AM
    Wednesday, January 16, 2013 4:13 PM
    Moderator
  • So it sounds as if I have to start getting my head around visual studio express. Thanks for your help
    Friday, January 18, 2013 6:55 AM
  • Visual Studio Express could do the Open XML part, but not create a COM Add-in. That would require the Professional edition or a third-party tool such as Add-in Express.

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, January 18, 2013 4:19 PM
    Moderator
  • Thanks that clears that up.

    Would NetOffice which I believe is free be a suitable alternative to developing COM add-ins for MS Office.

    Also in terms of programming language VB or C#. For me I thought VB since the syntax would be similar to VBA and would be easier to learn however I do not know the advantages or disadvantages of using either for COM Add-ins.

    What are your thoughts?

    Saturday, January 19, 2013 12:54 AM
  • I'm not familiar with NetOffice, so I can't say. You'd have to ask in a venue where that is discussed.

    In essence, VB.NET and C# have the same capabilities - both work with the namespaces (classes) in the .NET Framework; once the code is compiled it is the same. And certainly, as far as this discussion has gone, there'd be no difference. So yes, it would make sense for you to work with VB.NET rather than familiarize yourself with a completely new syntax.


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, January 19, 2013 6:38 AM
    Moderator
  • Great thanks for that confirmation. I will let you know how I go with NetOffice.

    Thank you for your time and assistance.

    Saturday, January 19, 2013 11:03 AM
  • Hi

    Currently making the custom pane in VB using visual studio express and the VSTO form NetOffice. I understand the customtaskpane objects and collection but I want to use the open file dialog box, to return file names. What is the property or class that I should be looking at for the open file dialog box in word.

    Thanks 

    Monday, February 18, 2013 4:10 AM