Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marceepoo - 21 Mar 2008 17:48 GMT
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
Tony Strazzeri - 24 Mar 2008 05:04 GMT
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
>
[quoted text clipped - 3 lines]
>         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.
Marceepoo - 24 Mar 2008 15:21 GMT
Thank you.  Much appreciated.          
                                           marceepoo

> The result of Selection.Font.Hidden will be:
>    true if ALL of the text is formatted as hidden
[quoted text clipped - 30 lines]
> Cheers!
> TonyS.
Jean-Guy Marcil - 24 Mar 2008 17:32 GMT
> The result of Selection.Font.Hidden will be:
>    true if ALL of the text is formatted as hidden
[quoted text clipped - 12 lines]
> 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.
>
[quoted text clipped - 8 lines]
> 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.
Tony Strazzeri - 24 Mar 2008 22:50 GMT
> 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:
[quoted text clipped - 5 lines]
>
> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.