PDA

View Full Version : Hide all non-green text



Fantpmas
09-20-2013, 01:45 AM
I want to hide all non-green text in a Word document to be able to process it easier in a translation environment. Only green text needs translation and setting the other text to hidden, makes that other text untranslatable in thetranslation environment.

The following macro has two problems:



Sub HideNonGreenText()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = "*"
.MatchWildcards = True
.Wrap = wdFindAsk


While .Execute
If rDcm.Font.ColorIndex <> wdGreen Then


rDcm.Font.Hidden = True


End If
Wend
End With
End Sub




It's slow
I have to add .Wrap = wdFindAsk for it to go forward. Ideally it would just stop at the end of the document without prompting me.


Any tips would be very much appreciated.
Thomas

gmaxey
09-20-2013, 07:28 AM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
ActiveDocument.Range.Font.Hidden = True
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "*"
.Font.ColorIndex = wdGreen
.MatchWildcards = True
.Format = True
.Replacement.Text = "^&"
.Replacement.Font.Hidden = False
.Execute Replace:=wdReplaceAll
End With
lbl_Exit:
Exit Sub
End Sub

Fantpmas
09-23-2013, 12:52 AM
Thanks Greg, but doesn't seem to work, everything stays hidden, the green text doesn't become unhidden.

gmaxey
09-23-2013, 06:23 AM
It works here so that means that your "green" text is most likely some shade of green other than wdGreen. You could try determining the long color value and using that instead:

Msgbox Selection.Font.Color



Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
ActiveDocument.Range.Font.Hidden = True
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "*"
.Font.color = 5287936 'long value
.MatchWildcards = True
.Format = True
.Replacement.Text = "^&"
.Replacement.Font.Hidden = False
.Execute Replace:=wdReplaceAll
End With
lbl_Exit:
Exit Sub
End Sub

Fantpmas
09-23-2013, 07:10 AM
I'd been thinking the same thing, but the long value is indeed 5287936. I tested with other colours, same happens there. Everything is hidden.

See youtu.be/_5juFIgm0f4

gmaxey
09-23-2013, 10:16 AM
Sorry. I'm out of ideas.

SamT
09-23-2013, 07:33 PM
:dunno:

Shouldn't you be using

Set Rng =Find Format:=Font.Color =5287936
If Not Rng Is Nothing Then Rng.Hidden = False
Or something like that