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 / February 2006

Tip: Looking for answers? Try searching our database.

Need to refine simple code ending in Wend

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave Neve - 11 Feb 2006 11:12 GMT
Hello

Helmet gave me some code as usual and I have managed to create a second
macro from the original to handle characters instead of words (one small
step for man, one gaint leap for nevekind)

The macro is a follows
_____________________________________________

Sub GOL()

' GOL Macro (Go one letter)
' Macro créée le 11/02/2006 par Dave Neve
'
Dim l As Long
Application.ScreenUpdating = False
ActiveWindow.View.ShowHiddenText = True
l = 1
With Selection.Cells(1).Range
   While .Characters(l).Font.Hidden = False
     l = l + 1
   Wend
   .Characters(l).Font.Hidden = False
End With
ActiveWindow.View.ShowHiddenText = False
Application.ScreenUpdating = True
End Sub

_____________________________________________________________________________________________

The problems comes when I reach the end of the last word but don't
necessarily know as I can't remember how many words are in the cell.

I click on the macro again and nothing happens, probably cos there is a
space character.

But the next click is 'fatal'.

There is an error that the 'collection object'(not sure of exact term in
English) can't be found and worse still, this seems to trigger Word to
activate 'show masked text' in the whole table which I then have to untick
manually.

Can anyone help please?

Thanks
Helmut Weber - 11 Feb 2006 14:04 GMT
Hi Dave,

the question is, what you want to do.
If you change words to characters,
then the macro would unhide the first hidden character
and exit afterwards.
Whereby it is assumed, that there is at least
one hidden character somewhere in the cell!

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Dave Neve - 11 Feb 2006 18:14 GMT
Hi

It's hard to be clear but the macro seems to find the next character every
time I activate it and so the word is gradually revealed and this is fine.

The problem comes when I activate the macro twice more 'by accident'
thinking that there might be another word in the cell.

This causes an error which says that the 'collection object'(not sure of
exact term in
English) can't be found and worse still, this seems to trigger Word to
activate 'show masked text' in the whole table which I then have to untick
manually.

This is the error I need to stop.

Hope this is clear.

Regards

Dave Neve

> Hi Dave,
>
[quoted text clipped - 4 lines]
> Whereby it is assumed, that there is at least
> one hidden character somewhere in the cell!
Helmut Weber - 11 Feb 2006 23:12 GMT
Hi Dave,

one method would be to check,
whether there is hidden text at all.

Public Sub test5056()

Dim l As Long
Dim rTmp As Range
Set rTmp = Selection.Cells(1).Range
rTmp.End = rTmp.End - 1
Application.ScreenUpdating = False
ActiveWindow.View.ShowHiddenText = True
l = 1
' ------
With rTmp.Find
  .Font.Hidden = True
  If Not .Execute Then
     ActiveWindow.View.ShowHiddenText = True
     Exit Sub
  End If
End With
' ------
With rTmp
   While .Characters(l).Font.Hidden = False
     l = l + 1
   Wend
   .Characters(l).Font.Hidden = False
End With
ActiveWindow.View.ShowHiddenText = False
Application.ScreenUpdating = True
End Sub

As Tony told us in the previous thread,
a range has a property TextRetrievalMode,
which could be useful, too, if you prefer
a solution without using
ActiveWindow.View.ShowHiddenText.

Which I had used anyway,
if I had known about it.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber - 11 Feb 2006 23:27 GMT
Hmm..., one of these days,

  If Not .Execute Then
     ActiveWindow.View.ShowHiddenText = false
     ' which is what you want, probably
     Exit Sub
  End If

HW
Dave Neve - 12 Feb 2006 08:22 GMT
Hi

I took out

rTmp.End = rTmp.End - 1

which made the macro jump a line down to reveal the wrong words (one cell
down) and I even managed to 'convert' your macro again to get it to work on
'words' as well as characters.

Unfortunately, I have to admit that I can't really follow the logic of this
macro with all its true and falses, hide and show and the conditions set
inside one another.

But thanks a million

Dave Neve

> Hmm..., one of these days,
>
[quoted text clipped - 5 lines]
>
> HW
Helmut Weber - 12 Feb 2006 11:50 GMT
Hi Dave,

1st:
create a range and set it to the cell
2nd:
move the range's end one character to the left
so that the end-of-cell mark is not included,
which is always a good idea for a couple of reasons
3rd:
show hidden text
4th:
check whether there is hidden text at all
search in the range for hidden text
if not .execute means:
if no hidden text was found
then hide hidden text and exit

if hidden text was found then

5th
set up a counter and check character by character
as long as the character with the number of the
counter is not hidden.
If checking character by character finds a hidden
character, then the loop ends.
6th: The font of the actual character is set to not hidden

end

FAR BETTER would be to use TextRetrievalMode ("thanks Tony")

Use a sample paragraph and forget about cells first:

The quick brown fox jumps over the lazy dog¶

Sub HideEverySecondWord()
Dim rTmp As Range
Dim lCnt As Long
Set rTmp = Selection.Paragraphs(1).Range
lCnt = 0
With rTmp
  .TextRetrievalMode.IncludeHiddenText = True
  For lCnt = 2 To .Words.Count Step 2
     .Words(lCnt).Font.Hidden = True
  Next
End With
End Sub
' -----------------------------------------
Sub ShowFirstHiddenWord()
Dim rTmp As Range
Set rTmp = Selection.Paragraphs(1).Range
With rTmp
  .TextRetrievalMode.IncludeHiddenText = True
  With .Find
     .Font.Hidden = True
     .MatchWholeWord = True
     If .Execute Then
        rTmp.Words(1).Font.Hidden = False
     End If
  End With
End With

The difficulty seems to be,
that there are so many ways to do it.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
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.