PDA

View Full Version : Save formatted text in a variable / attach hidden text to a document



asifbaig
10-28-2011, 07:48 AM
Hi folks. I've written a small program for purposes of medical reporting that creates a new document based on a template and fills in the patient data that it has been given from a form. At the end of the document, it is supposed to write the names of the consultants who are going to sign the report, along with their designation/degrees etc. The name has to appear in bold and the qualifications in a smaller, non-bold font.

To that end, I created a borderless table near the end of document and made the program load the names of the consultants from "seniorlist.doc" which had a single table containing the names/degrees of seniors with the proper formatting already applied. The plan is to pick up the entire contents of a cell and put them in the document that is being created. What command should I use so that the formatting is preserved?


This is not, however, the reason for this post. Once a report has been created, I would like the names of the consultants to be changeable so I created a form and attached it to the Normal template, making it available in every document. This form examines that borderless table in the current document and displays its contents. Along the side, it loads the names from that "seniorlist.doc" file and displays them in a listbox making it easy to pick names from the entire list.

Now the problem, and the reason for the topic, is that in order to load the names from seniorlist.doc, the file has to be opened, with its own window appearing in the taskbar (at least I think so). And seniorlist.doc has to be closed when the names have been inserted (so I added that command in the "Change Consultants" button) but if someone changes their mind and closes the dialogue by pressing the red X close button, the seniorlist.doc will remain open.
Considering the average computer literacy of the people who will be using this program, I'd like some alternative instead of exposing my program's vital components for accidental editing.

So I wondered:

1. Is there a way to save the formatted text in a variable? In that case, all I'd have to do is to open the seniorlist.doc once, load all the names and degrees in an array and close it, then use the array to populate the listbox as well as replace names.

OR

2. Is there a way to attach hidden text to a document that can be accessed by code but not easily visible to the average user? Kind of like having a separate workbook in Excel (perhaps called a wordbook ;) )? That way, upon the generation of a new report, I could throw the list of consultants in that second "wordbook", load it from there instead of using a separate seniorlist.doc file and since the wordbook would be hidden, it would not confuse the average user nor appear when printing that report.

OR

3. Finally, and most importantly, the reason I went into such detail about the working and purpose of the program is to know if there's a better and simpler way of doing what I am doing. I've not had much experience with VBA, only with QBasic back in the time of DOS, and I still find myself trying to solve programmatic problems with the methods I learnt in that ancient time.

I hope the details I provided were not confusing. Please tell me if any portion needs elaboration.

gmaxey
10-28-2011, 08:08 AM
1. No. Variables are pure plain text only. No formatting.
2. What you could do is create AutoText\BuildingBlocks entries that define you formatted text and use the titles (names) of these entries to populate your listbox.
3. I can't really answer this because I don't really understand exactly what you are trying to do.

Just as a stab in the dark, you might find something useful here:
http://gregmaxey.mvps.org/Ribbon_Gallery_Control.htm

asifbaig
10-29-2011, 03:49 AM
I want to be able to:

a. Pick formatted text from "somewhere" and insert it into a document at a specified place.

b. Once that text has been inserted, I want to be able to change it via macro if needed, to some other text (which will also be formatted).

Now:
1. Could it be possible if the macro sent the text to the clipboard and then pasted it at the indicated location? Copying to clipboard would preserve the formatting, no?

2. If formatted text cannot be stored in a variable, does that mean it cannot be stored in a custom made object either?


I saw the link you posted and it seems like it could help but my knowledge of XML is woefully inadequate.

gmaxey
10-29-2011, 04:25 AM
You can store formatted text in buidling blocks. Buillding blocks are stored in a buildling block template or can be stored in the document template. The link posted (in addition to the XML to create the ribbon) contains the VBA code for inserting building blocks.

asifbaig
11-01-2011, 01:41 PM
Thanks. I'll look into the building blocks. I'm guessing this will limit the portability of the program since if I move it to a new machine, that will need to have those building blocks predefined.