Revealing hidden words

D

Dave Neve

Hi

I've written the following simple bit of code (to reveal the first hidden
word in a cell) but as usual, it doesn't work as expected
______________________________________________________
GetOneWord()
'
' Macro enregistrée le 10/02/2006 par Dave Neve

Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

With Selection.Font
.Hidden = False

End With
End Sub
_______________________________________________________

It reveals all the hidden words in the cell and not just the first one.

Why is this please?

Thanks

Dave Neve
 
H

Helmut Weber

Hi Dave,

not that simple.
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

Selects the entire cell, if the next word
is the end-of-cell mark, and, here and now,
does more unexpected, not reproducable things.

It seems, if you want to access hidden text,
you have to show it first.

How about this one:

Sub test501()
Dim l As Long
Application.ScreenUpdating = False
ActiveWindow.View.ShowHiddenText = True
l = 1
With Selection.Cells(1).Range
While .Words(l).Font.Hidden = False
l = l + 1
Wend
.Words(l).Font.Hidden = False
End With
ActiveWindow.View.ShowHiddenText = False
Application.ScreenUpdating = True
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jezebel

Because that extends the selection to include the first non-hidden word,
then reveals any hidden words that might have been in between.

As is so often the case, the problem comes from using the Selection object
when you should be using a Range.

Dim pRange as Word.Range
Dim pWord as Word.Range

set pRange = Selection.Cells(1).Range
For each pWord in pRange.Words
if pWord.Font.Hidden then
pWord.Font.Hidden = false
exit for
end if
Next
 
H

Helmut Weber

Hi Jezebel,

excellent!

But completely illogical.

Do you have any explanation, for this:

Text in the cell:
Wort1 Wort2 Wort3 Wort4

Wort2 and Wort4 are hidden and not displayed.

Sub test00987354()
Dim pRange As Word.Range
Dim pWord As Word.Range
Set pRange = Selection.Cells(1).Range
For Each pWord In pRange.Words
MsgBox pWord ' = "Wort1" !!!
If pWord.Font.Hidden Then
pWord.Font.Hidden = False
' unhides Wort2 ???
Exit For
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
T

Tony Jollans

To work properly this code must ensure it processes hidden text, whether
displayed or not ...

Dim pRange as Word.Range
Dim pWord as Word.Range

set pRange = Selection.Cells(1).Range
'===== Following line added =====
pRange.TextRetrievalMode.IncludeHiddenText = True
'=========================
For each pWord in pRange.Words
if pWord.Font.Hidden then
pWord.Font.Hidden = false
exit for
end if
Next
 
H

Helmut Weber

Hi Tony,

excellent,
pRange.TextRetrievalMode.IncludeHiddenText = True

there is always something to learn.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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