Change font color in Text boxes

L

LadyMiss22

You guys have really been a big help. This is my first time dealing with
VBA..and the teacher has loved it so far..

I have the following code to replace bold text with whit text, and vice
versa, essentially making the text disappear and re appear. How do I get
the macro to include text in text boxes? It seems to skip over these. Also,
I tried adding a table instead of a text box and the text inside was
converted however this also made the macro "hang" and made Word crash. Any
help would be appreciated.

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 = 1#
sLine = msoFalse
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 = 0#
sLine = msoTrue
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
End Sub
 
D

Doug Robbins - Word MVP

See the article "Using a macro to replace text where ever it appears in a
document including Headers, Footers, Textboxes, etc." at:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

I am not sure what you mean by "use tables and manipulate the code"


--
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

Great thank you, I actually had just found that article when you replied.

Problem started because I added another table to the document with bolded
text so that this text may also 'disappear' (this had worked with the table
already in the document) however when I ran the macro the macro button I
created stayed depressed and blinked continuously, then word "does not
respond" and has to be shut down.

I added text boxes to substitute but would like to use tables. Any idea why
this is happening?
 

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