Capturing 20-30 defined segments of formatted  MS Word text as separate VBA variables

Posted on 2011-05-01
Last Modified: 2012-05-11
I have an authoring application in MS Visio, which outputs data in JSON format to drive a web-based application. Visio was chosen as a development tool because intelligent shapes greatly reduce expert authoring time and reduce authoring errors. However, there is a substantial section of entry-level authoring which simply involves typing formatted text and numerals into 20-30 visio Shapes, each of which gathers data for a separate JSON content field.

I am considering removing this entry-level authoring layer out of the Visio application, and having the text and numerals entering into fields in a more widely available and less expensive application, such as MS Word or an Office form. As a result the entry level authoring would be cheaper and easier.

I ask whether there is a practicable way of capturing text (some of which is multi-paragraph) from defined 'fields' in a word document, and converting each to a public variable, or dictionary item, in VBA. Then I can 'suck it up' into the visio application.

A key issue is the formatting of the entered text. Currently an expert author carries out typical microsoft WYSIWYG text formatting in Visio. The format of text in each shape is defined by format code in each Shape's shapesheet. VBA converts thisVISIO text  into the HTML that is required for the JSON output to send to the web-based app.

One additional complication is that It would also be necessary for the Word-derived text variables to be displayed in Visio shapes: this to meet layout requirement in the visio authoring app.
I do know that the format of text written in Word can be copied and pasted into Visio shapes, without loss or change of format. So I feel there must be a common formatting system at work in both applications.

My questions are:
1. Can I use MS Word as an intelligent 'form' to receive data in effectively 20-30 'fields' (a few of which with be multi-paragraph text.
2. Can that text be stored as VBA public variables (eg in dictionaries) which can be shared with the Visio app.
3. If this is a go-er, how is text formatting data managed in Word and transmitted in data strings?

This is a preliminary question, seeking a practical way forward and advice on avoiding bad strategies (possibly including the above?). If you could point me in the right direction via urls etc, I'd hope to wise up and think further.

PS: from what I understand, MS SharePoint cannot be used for the entry level author to type text into visio fields on a web-based view of a visio diagram.

Question by:Kelvin4
    LVL 76

    Expert Comment

    1. It is possible to designate, e.g. by bookmarks,  particular blocks in a Word document.
    2. They can be held as VBA variables, as Strings if formatting is not to be included or as Ranges, if formatting is relevant
    3. You would probably have to use an external format, such as HTML, RTF or XML if the formatting is to be understood outside of Word.
    LVL 76

    Expert Comment

    Note that copying and pasting looks like the proverbial duck gliding across the water. There is a lot of paddling going on under the surface.

    Author Comment

    Graham: thank you.  Just like to check through my understanding of point 1...

    1. Bookmarks, I set these from the fluent toolbar, enumerate them via vba, and work up an understanding of the representation of my pages of data fields.

    Point 3. "You would probably have to use an external format, such as HTML, RTF or XML if the formatting is to be understood outside of Word".  
    Here I'm unsure what is meant by using an external format, and I'd like to avoid XML for now becuase of lead time and inexperience with it.  I dont see a way of saving Word 2010 files as HTML or RTF, though there seems to be a method for RTF, since technet says:

    "RTF file format     The RTF file format is no longer enhanced to include new features and functionality. Features and functionality that are new to Word 2010 and future versions of Word are lost when they are saved in RTF. In addition, Word 2010 supports a new converter interface based on Open XML Formats."

    I only seek basic formatting controls, nothing at all new, but how do I save as RTF - or is something else required.

    Please could you lead me a bit further here, as I've run out of clues.


    LVL 76

    Accepted Solution

    Yes, you select the text that you want to bookmark, and use the ribbon or tool bar (in older Word versions) to insert a bookmark.

    Unless you are using any of the new features (e.g. content controls), any save format will preserve the content. Incidentally the default save format is zipped XML.

    Actually, I'm not sure if the save format is relevant. I was supposing that you would need to work on saved files as opposed to using the Word Object model on an open document. As I understand it, JSON is based on JavaScript, so it would make sense to try to work with an HTML save


    Author Closing Comment

    It helped me get started, which is what I asked for. The formatting issue is not trivial one suspects.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
    Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
    This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
    The viewer will learn how to install the Spideroak software to backup files. Start your default browser: In the URL location bar type and press enter: When you see the spideroak site, click the “Try for free” button in the upper ri…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now