vba to determine if text attribute (eg. of a table) is "hidden"

M

Marceepoo

I can't figure out how to use vba to ascertain whether the text attribute of
a table (or other text) that is selected (or which I identify using a range
object) is "hidden".

Does anyone have any suggestions where I could get info about this?
I'm using Word Profl. 2003 in WinXp.

Thanks,
marceepoo

p.s. The following code contains my last failed attempt. Any suggestions
for corrections would be much appreciated.


Sub HiddnOrNot()

Dim oRng1 As Table

With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.GoTo What:=wdGoToBookmark, Name:="Tableofreplacements"
Selection.Tables(1).Select

Set oRng1 = Selection.Tables(1)

If Selection.Font.Hidden = False Then
' If oRng1.Range.Font.Hidden = False Then
MsgBox "Table is visible, i.e., Hidden = False - Success!" & _
vbCrLf & "Press OK to make it invisible"

oRng1.Range.Font.Hidden = True

Selection.HomeKey Unit:=wdStory

Selection.GoTo What:=wdGoToBookmark, Name:="Tableofreplacements"
Selection.Tables(1).Select
Set oRng1 = Selection.Tables(1)

Else
MsgBox "Table is INvisible, i.e., Hidden = True - Press Ok to fix
this.!"
oRng1.Range.Font.Hidden = False
MsgBox "Table sb visible now!"
End If

End Sub
 
T

Tony Strazzeri

The result of Selection.Font.Hidden will be:
true if ALL of the text is formatted as hidden
False if All of the text is formatted as NOT hidden

Undefined if there is a mixture.

Your code does not allow for the last option

Also:

Selection.GoTo What:=wdGoToBookmark, Name:="Tableofreplacements"
Selection.Tables(1).Select

These two lines may change the selected table. First you are
selecting a table by a bookmark (presumably) places around it, then
you care changing the selection to be the first table in the document.

You only need one or the other. They may not be the same thing.

oRng1.Range.Font.Hidden = True

Selection.HomeKey Unit:=wdStory

Selection.GoTo What:=wdGoToBookmark, Name:="Tableofreplacements"
Selection.Tables(1).Select
Set oRng1 = Selection.Tables(1)

Here there is the same problem as above and I can't see what these
last three lines are there for anyway!

Hope this helps.

Cheers!
TonyS.
 
M

Marceepoo

Thank you. Much appreciated.
marceepoo

Tony Strazzeri said:
The result of Selection.Font.Hidden will be:
true if ALL of the text is formatted as hidden
False if All of the text is formatted as NOT hidden

Undefined if there is a mixture.

Your code does not allow for the last option

Also:



These two lines may change the selected table. First you are
selecting a table by a bookmark (presumably) places around it, then
you care changing the selection to be the first table in the document.

You only need one or the other. They may not be the same thing.



Here there is the same problem as above and I can't see what these
last three lines are there for anyway!

Hope this helps.

Cheers!
TonyS.
 
J

Jean-Guy Marcil

Tony Strazzeri said:
The result of Selection.Font.Hidden will be:
true if ALL of the text is formatted as hidden
False if All of the text is formatted as NOT hidden

Undefined if there is a mixture.

Your code does not allow for the last option

Also:



These two lines may change the selected table. First you are
selecting a table by a bookmark (presumably) places around it, then
you care changing the selection to be the first table in the document.

In fact,
Selection.Tables(1).Select
selects the first table in the Selction, not the document. For that, you need:
ActiveDocument.Tables(1).Select
You only need one or the other. They may not be the same thing.



Here there is the same problem as above and I can't see what these
last three lines are there for anyway!

If all the OP want to do is create a range object, then the code should have
been:

Dim oRng1 As Range

Set oRng1 =
ActiveDocument.Bookmarks("Tableofreplacements").Range.Tables(1).Range

Do not uset he Selection object unless absolutely necessary.
 
T

Tony Strazzeri

In fact,
   Selection.Tables(1).Select
selects the first table in the Selction, not the document. For that, you need:
   ActiveDocument.Tables(1).Select

Jean-Guy Marcil Of course you are quite correct. My oversight.

If all the OP want to do is create a range object, then the code should have
been:

Dim oRng1 As Range

Set oRng1 =
ActiveDocument.Bookmarks("Tableofreplacements").Range.Tables(1).Range

Do not uset he Selection object unless absolutely necessary.

I agree with this as well. It is usually better to use the range
object I usually don't make a big point about it because it is just
easier sometimes to use the selection object especially when you are
new or are having problems because you can see what is going on.

Cheers!
TonyS.
 

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