Forcing text and tables to hide

D

David

I've inherited several hundred small documents that have a couple of
templates attached to them to carry out specific tasks.

One of these templates prepares the document for printing, which means
that the document history section is deleted. Unfortunately, due to
human error a print ready document has been saved which means that the
document history is lost.

Easy, the solution is to hide the content of the document history
section when printing. However, this is complicated by a table that
captures information like author, date modified, document path,
template version used, etc. of which some of the information is already
hidden.

So I've written a macro that hides the document history section and
then, because hide is a toggle, hides the text that had become
unhidden. I've also tried revealing the hidden text and then hiding the
section, but I keep getting the same result.

After the macro completes the table borders of the text that was hidden
before the macro ran are still left in place, which is undesirable.
I've tried the process manually, by stopping the macro then doing
Format | Font | Hide, which works perfectly.

Can anyone help identify why the table borders are still showing when
the following macro runs?

Sub UpdateDocProperties()
' Define the range for the following macro
Dim docRange As Range
Set docRange = ActiveDocument.Bookmarks("DocControl").Range
' Go to the start of the document
Selection.HomeKey Unit:=wdStory
' Message box so that I know what's happening
MsgBox ("Hiding all text")
' Hide the text in DocControl section
docRange.Font.Hidden = True
' Message box so that I know what's happening
MsgBox ("Hide template text")
' Hide the text that has been revealed
With docRange.Find
.Font.Hidden = False ' find hidden text
.Style = "CharAuthorFlags" ' make sure that it's the right
style
.Wrap = wdFindStop
.Replacement.Font.Hidden = True
.Execute Replace:=wdReplaceAll
End With
End Sub
 
J

Jezebel

It's a little hard to fathom, given the lousy description of the task and
the truly execrable quality of the macro code; but the short answer is that
the code doesn't hide the table, only the text within it.
 
D

David

Jezebel,

You must write help fro Microsoft. You've just conformed what I already
know but not given me any clue how to solve my problem.

This is exactly what does happen; the code hides the text within the
table and not the table. How do I get the code to hide the table and
the text?

If there is a list for 'people who know nothing about VBA but want to
do something' please point me in that direction, but I though that
word.vba.beginners was a good place to start.
 
J

Jezebel

You asked why the table was still showing, and the answer is, because your
code doesn't hide it.

If the question is, how do I hide a table? --

ActiveDocument.Tables(1).Range.Font.Hidden = True

(replace '1' as needed)
 
D

David

Jezebel,

That was most helpful, thank you. I do like the way that it elegantly
hides the table without all the screen flashing that my code created.

However, there are some table rows that are already hidden in the table
and this line reveals these rows. What I would like to do is hide the
whole table including the rows that are already hidden.

Is this possible?
 
J

Jezebel

I don't understand how that could be happening, and I can't re-create the
problem. Create a table, hide some rows in it, then use the line of code to
hide the entire table -- the entire table is hidden; the previously hidden
rows don't suddenly appear. What else is going on in your code?
 
D

David

Jezebel,

It would seem that the problem is caused by the style used in the last
three rows of the table. When I change the styles to the default 'Table
Cell' style the whole table disappears.

I've change the macro to clear the formatting of the table and then
hide the whole table. This works. When I reveal the table I change the
last three rows back to the original style so that it conforms to the
style guide.

Thank you for all your time on this problem, it has been an excellent
learning experience.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top