Re: Round function evaluates to zero if bookmark is hidden text
- From: "Jay Freedman" <jay.freedman@xxxxxxxxxxx>
- Date: Tue, 6 Nov 2007 16:22:25 -0500
Thomas McLain wrote:
I have a document template that uses the round function, which is
used to round the value of another bookmark. When that bookmark is
hidden text, the round function evaluates to zero, which is
incorrect. When the bookmark is displayed, the round function
evaluates properly. I need the bookmark to remain hidden text, but I
need the round function to work properly. How do I do so?
It isn't the Round function that's not working properly. If you're using the
..Range.Text of the bookmark and the text is hidden, the value of that
property is returned as the empty string, "". Passing that to the Val
function, explicitly or implicitly, returns the number 0. That's what is
being passed to the Round function.
The solution is to set the TextRetrievalMode.IncludeHiddenText property of
the range to True, so it sees the text regardless of whether it's hidden.
Here's a sample:
Sub demo()
Dim myVal As Single
Dim oRg As Range
Set oRg = ActiveDocument.Bookmarks("bk1").Range
oRg.TextRetrievalMode.IncludeHiddenText = True
myVal = Round(Val(oRg.Text), 2)
MsgBox myVal
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
.
- Prev by Date: Re: Save As i.e. "Ln 1, Col 1-5"
- Next by Date: Re: Sending debugging messages to a second document.
- Previous by thread: Re: Save As i.e. "Ln 1, Col 1-5"
- Next by thread: Re: Round function evaluates to zero if bookmark is hidden text
- Index(es):
Relevant Pages
|