Macro to toggle Colors??

L

LadyMiss22

I have another q for you guys..

IS it possible to toggle between colors in word? E.g. I have a paragraph
with Automatic color black, bolded words and want a macro to convert words or
characters that are bolded in black to the color white ..essentially to
make the text dissappear..

I'd also like to be able to turn this on and off so I can make the text go
back to Black and Bold.

Any help?
 
D

Doug Robbins - Word MVP

Use:

Dim Flag As Boolean
Flag = False
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorWhite
With Selection.Find
If .Execute = True Then
Flag = True
End If
Do While .Execute(FindText:="", MatchWildcards:=False,
MatchCase:=True, Wrap:=wdFindContinue, Forward:=True) = True
With Selection.Font
.Color = wdColorAutomatic
.Bold = True
End With
Loop
End With
If Flag = True Then
Exit Sub
End If
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
Selection.Find.Font.Bold = True
With Selection.Find
Do While .Execute(FindText:="", MatchWildcards:=False,
MatchCase:=True, Wrap:=wdFindContinue, Forward:=True) = True
With Selection.Font
.Color = wdColorWhite
End With
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LadyMiss22

Thanks Doug,

I keep getting an error on this wording:

Do While .Execute(FindText:="", MatchWildcards:=False,
MatchCase:=True, Wrap:=wdFindContinue, Forward:=True) = True


Error MSG: Compile Error, Expected: expression

I am running Word 03 if that makes a difference.
 
J

Jay Freedman

Those two lines should be one line (the posting software forced a line wrap in
the middle of the line). Put the cursor before MatchCase and press the Backspace
key.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
L

LadyMiss22

Silly of me, I'd say I knew that but I didn't :p

Worked great! ONE more thing..Graham wrote the following code (he's
awesome), how do I incorporate this code so some word art disappears when the
text goes white and appears when the text is turned back to black?

With sSource
For Each aShape In .Shapes
If aShape.Type = msoTextEffect Then
aShape.Select
With Selection
.ShapeRange.Fill.Transparency = sTrans
.ShapeRange.Line.Visible = sLine
End With
End If
Next aShape
End With


This is what I have..The word art appears but I can't get it to disappear:
Sub ShowAnswers()
Dim Flag As Boolean
Dim aShape As Shape
Dim sLine As String
Dim sTrans As String
Dim sSource As Document
Set sSource = ActiveDocument
Flag = False
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorWhite
With Selection.Find
If .Execute = True Then
Flag = True
End If
Do While .Execute(FindText:="", MatchWildcards:=False, MatchCase:=True,
Wrap:=wdFindContinue, Forward:=True) = True
With Selection.Font
..Color = wdColorAutomatic
..Bold = True
End With
Loop
End With
If Flag = True Then
Exit Sub
End If
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
Selection.Find.Font.Bold = True
With Selection.Find
Do While .Execute(FindText:="", MatchWildcards:=False, MatchCase:=True,
Wrap:=wdFindContinue, Forward:=True) = True
With Selection.Font
..Color = wdColorWhite
End With
Loop
End With

If ActiveWindow.View.ShowHiddenText = False Then
Options.PrintHiddenText = False
sTrans = 0#
sLine = msoTrue
Msg = "Hidden Text Hidden"
Else
Options.PrintHiddenText = True
sTrans = 1#
sLine = msoFalse
Msg = "Hidden Text Displayed"
End If
With sSource
For Each aShape In .Shapes
If aShape.Type = msoTextEffect Then
aShape.Select
With Selection
.ShapeRange.Fill.Transparency = sTrans
.ShapeRange.Line.Visible = sLine
End With
End If
Next aShape
End With

End Sub
 
D

Doug Robbins - Word MVP

I assume that the formatting of text as white has superseded the use of
hidden text.

Sub ShowAnswers()
Dim Flag As Boolean
Dim aShape As Shape
Dim sLine As String
Dim sTrans As String
Dim sSource As Document
Set sSource = ActiveDocument
Flag = False
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorWhite
With Selection.Find
If .Execute = True Then
Flag = True
End If
Do While .Execute(FindText:="", MatchWildcards:=False, MatchCase:=True,
_
Wrap:=wdFindContinue, Forward:=True) = True
With Selection.Font
.Color = wdColorAutomatic
.Bold = True
End With
Loop
End With
If Flag = True Then
sTrans = 0#
sLine = msoTrue
With sSource
For Each aShape In .Shapes
If aShape.Type = msoTextEffect Then
aShape.Select
With Selection
.ShapeRange.Fill.Transparency = sTrans
.ShapeRange.Line.Visible = sLine
End With
End If
Next aShape
End With
Exit Sub
Else
sTrans = 1#
sLine = msoFalse
End If
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Color = wdColorAutomatic
Selection.Find.Font.Bold = True
With Selection.Find
Do While .Execute(FindText:="", MatchWildcards:=False, MatchCase:=True,
_
Wrap:=wdFindContinue, Forward:=True) = True
With Selection.Font
.Color = wdColorWhite
End With
Loop
End With
With sSource
For Each aShape In .Shapes
If aShape.Type = msoTextEffect Then
aShape.Select
With Selection
.ShapeRange.Fill.Transparency = sTrans
.ShapeRange.Line.Visible = sLine
End With
End If
Next aShape
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

LadyMiss22

You are awesome! I actually meant to have the art appear not disappear with
the white text but I was able to change it, solved!

Thank you Mr. Robbins!! :)
 

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