PDA

View Full Version : Solved: Neither True nor False?!



efto
05-26-2006, 04:20 AM
Can somebody help me to solve this?
There is one table in the attached document. The font of every row is not Hidden, but when whole table is checked then is neither True nor False?!

Option Explicit
Sub CheckHidden()
Dim myTable As Range
Set myTable = ActiveDocument.Tables(1).Range
If myTable.Font.Hidden = True Then
MsgBox "True"
Else
If myTable.Font.Hidden = False Then
MsgBox "False"
Else
MsgBox "Neither True nor False?!"
End If
End If
Set myTable = Nothing
End Sub

Andy Pope
05-26-2006, 05:01 AM
Hi,

The value returned is wdUndefined.
I think you may have to check at the rows or columns level.

efto
05-26-2006, 05:41 AM
Thanks for the info!

I found a workaround by checking every row, but I was just curious why is the value returned wdUndefined when every single row is not Hidden.

fumei
05-26-2006, 03:49 PM
It may help to note that you will never get ANYTHING but unDefined. Your code will always return "Neither True or False?!".

A table may have a .Font property but there is no real .Font property. Try this.Dim myTable As Range
Set myTable = ActiveDocument.Tables(1).Range

MsgBox myTable.Font.NameYou will get a blank message box. NO error. There is no error even if you explicitly set the .FontDim myTable As Range
Set myTable = ActiveDocument.Tables(1).Range

myTable.Font.Name = "Arial"No error, yet MsgBox myTable.Font.Namewill still return a blank message box. Try this. Make the table Arial first. Dim myTable As Range
Set myTable = ActiveDocument.Tables(1).Range
myTable.Font.Name = "times roman"
MsgBox myTable.Font.NameYES! the table will in fact be made into Times Roman...but the name will still be blank! You can set the value, but you can never return it. And again: Dim myTable As Range
Set myTable = ActiveDocument.Tables(1).Range
myTable.Font.Name = "times roman"
myTable.Font.Bold = True
MsgBox myTable.Font.Name & " " & myTable.Font.BoldThe value returned by myTable.Font.Bold (even though the table HAS been made bold) will always be 999999 - unDefined. It will NEVER be True...or False.

fumei
05-27-2006, 06:36 AM
Just as a further aside....

Have four paragraphs, with different Bold attributes.

Paragraph 1 IS Bold
Paragraph 2 is NOT Bold
Paragraph 3 IS Bold
Paragraph 4 is NOT Bold

Select all four paragraphs.Sub SelectionBold_Maybe()
If Selection.Range.Font.Bold = True Then
MsgBox "True"
Else
If Selection.Range.Font.Bold = False Then
MsgBox "False"
Else
MsgBox "Neither True or False"
End If
End If
End Sub will always return "Neither True or False". Any discrepancy within the Range will return:

"...heck...I don't know."

Even a single character different will make the state unDefined.

More...

Styles. Styles on the other hand WILL give an error. Say you have two paragraphs, one set as "Blahblah1" style, the other as "BlahBlah2" style. Select them both.MsgBox Selection.Range.Stylewill return the dreaded run-time Error 91 - "Object variable or With block variable not set." The code can not set Selection.Range.Style because a range can not have TWO styles. Mind you, you certainly can have a range that HAS two styles...you just can't get information about the styles out. This applies for character styles as well.

efto
05-31-2006, 11:49 PM
Hi Gerry,
Thank you for your very detailed explanation!