Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using macros to show/hide a table

Status
Not open for further replies.

georgejr24

Technical User
Apr 11, 2005
4
CA
I have a document in word that I am going to use as a template. Part of this template has instructions on how to complete different sections. These instructions are in tables. I would like to be able to have a macro that will show and hide these tables as required. I also have other tables within the document that always need to be there. What would the code look like if this is possible. I am also looking for other ideas if this would not work.
 
It is not that easy, and you may need to think your design out more.

1. Why are these instructions in a table? Is there some requirement that they must be in a table, specifically?

2. How are you going to fire the event to make these instructions vsisible?

3. You mention "template". Are you using this as a real template? That is, it will be a .DOT file that will not be opened by the user, but cloned using File > New.

Instructions can be done as sort of pop-ups, but there is no Visible property of any given table, so you are going to have to think your requirements out more.

Gerry
See my Paintings and Sculpture
 
This template is actually a .doc file. It will be stored on a document management system and used by File > Save As or by versioning.

This template was created before I started here, but I have found some problems with the template which is why I am trying to complete these changes.

We had a show/hide function on the old template and it would show up in red text. Below this text was a line that is already wrote out to help the people know where to start typing in that section. For example,

This would be the show/hide text in red text.

Indented, this would be the normal text and have a phrase like Insert'purpose'here.

The problem that was occurring was that if, by accident, you clicked before the indentation the show/hide text would show up along with all the hidden text characters. Even if I tried to formate the white space in between it would still show the show/hide text.

So to combat that problem I tried formatting a table with its own style and border and then try to set up a macro that could hide these tables. Maybe even an 'If' statement where I could have it find the specific formatted tables or text.

If possible, I could send a Snag-It pic of the old and new version, and maybe the old show/hide code from the other template.
 
1. Then it is NOT a template. At least not as far as Word is concerned. It is a boilerplate document, but not a template. "Template", within Word is a very specific beast, and a .DOC file, is not a template. Real templates are cloned into an un-named document - an exact duplicate of the template, but "named" Document1. This is precisely what happens when you open work and get a blank document. It is, in fact, a cloned document of Normal.DOT - which is, a template. If you make your own template, INVOKING, or calling it, clones a copy. Any VBA code, or macros, or AutoText etc are contained within the new document/clone.

2. How are users filling in information? If they are using formfields, there is a Help function that can be used for any formfield. You can put your own text into this Help. Users can press F1 on a formfield and get your text.

3. This appears to call for better management of user input. Either by use of formfields, by use of automated navigation within the document using bookmarks, of even the creation of a data entry form with a UserForm.

Give me an idea of #2 - how, and WHAT are they entering. Little pieces of text? Huge chunks of text? Are they cutting and pasting from other documents? Are they making choices from a repeating list - say, 10 client names that they always will choose from? Could conditional logic be applied - say, they choose Client A from a list, then all the address, account number blah blah blah is automatically filled in other places in the document.

What are your requirements?

What are they filling in? Again, if you are using formfields, and the document is protected for forms, as they tab between formfields, you could easily have text that explains what the next field is about show up in the document. Then as they complete the formfield, that text wuold not just disappear, but be removed. Something like:


FORMFIELD_A is blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.

Now, as the user Tabs into FORMFIELD_A, you could have text appear BEFORE it as an explanation, like:

This field should contain information about Bugs Bunny.
FORMFIELD_A is blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.

When the user enters the information and Tab out, the expanation text is removed - not just hidden, but removed. It would go back just the formfield - but with the user entered information of course.

Bugs Bunny is blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.

There are lots of ways of getting information to a user. Again, if you are using formfields, you could have message boxes appears as they enter the field.

It is mostly about figuring out real requirements, and then simple good deaign. However, to repeat about your original post, there is no easy way to makea table "appear" or "disappear". You could do some sneaky things with ActiveX controls though.......


Gerry
See my Paintings and Sculpture
 
I have created a .dot template before, but for our company this will be a "template" that everyone uses to make up a standard operating procedure.

I am not to familiar with formfields, but I will look into it. The people who will be filling in these documents may not know how to use word that well. What we are trying to do is under each section (Objective, Purpose, Work Procedure, Scope, etc.) is have a place where they are supposed to fill in that information as well as a reference on what should be put in that section as well as an example. I am willing to get rid of the tables for the formfields if that would work better, but am trying to avoid creating something that is difficult to use. In some cases they could be filling in a large amount of text.

The message boxes would work I think, but I am not entirely sure how to do that. Is there a way that if it is button that it can be hidden if the document is printed? Can I format the message box to appear if a user clicks on the section heading?

My last question is whether or not I can format the show/hide text to be non-printable characters?
 
Documents that are primarily used for a user to input text can really use formfields. Properly designed, they are very easy for users.

essentially, (text) formfields are blocks of a document where someone types in text. Formfields, to function this way, MUST be in protected Sections.

First off, Section is a specific Word term for a structure of a document. You use of "Objective", "Purpose" as sections is a typographical term. To Word, a Section is a structural term. Formfields function in protected Sections.

You can make sections small. Say, one paragraph. In that paragraph you have a text formfield. When protected, the user CAN NOT access anything else in that Section. They can not type in it, edit it, format it. They can ONLY enter text into the formfield.

This is why, if the requirement is for someone to open a document, and enter text at specified locations - formfields are definitely the way to go. Set up, the user enters the text....done. The cursor moves from formfield to formfield, and that is it. You can automate the saving of the file, as formfields allow macros to run either OnEntry, or OnExit. So, for example, in your document, the user finishes the last formfield, tabs out of it, and the document co9uld easily save itself as a different name etc etc.

Formfields are PERFECT for people who do not know Word. If they are simply completing documents, properly set up, formfields work tickety-boom.

Now the one problem is...if there is a LARGE amount of text to be entered, then formfields are not a great way to do this.

Please expand on what your requirements actually are. You have these headings (Objective, Purpose etc etc). Is there any text there? What are they puting in there? Are they doing original writing - or copying from somewhere else?

Would an navigation system that moves the cursor to those headings help? How about a menu system for Objective, Purpose so that when the user selects that menu item, a message box appears explaining what they need to do there? How about when they select a menu item, the cursor goes there (to that location - Objective, Purpose etc etc). At that location is a table with the instructions and a macrobutton that says "Delete these instructions". They can click it, and the table will be removed.

You could also do a final macro that removes all those tables when you print, or when you save the file.

Define your needs.

Gerry
See my Paintings and Sculpture
 
For some guidance on how to insert non-printing instructions into a document (or a template), see my Date Calculations document at:
(url all one line)
and check out the topics 'Use a date test to provide pre-printing instructions' and 'Hide instructions at print time'.

Cheers
 
Here is what I ended up doing. I created a bookmark for each table within the section by selecting all the text in the table. Then I created a macro that would go to the bookmark, switch the table borders to none and select the text to be hidden. Then a did the exact opposite for the show button. It takes about 2 seconds to complete, but works very well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top