Looping through text boxes to change font

S

Santa Claus

Hi,

I'm wanting to create a macro to change the font in all text boxes with a
document. I'm guessing I need to select each box and change the
properties....one at a time. Each document has different types of objects
(Select All doesnt work).

If any one can help with code so make a simple loop macro, I'd appreciate
it.

Thanks
Santa
 
J

Jonathan West

Hi Santa

Something like this should put you on the right track

Dim oShape as Shape
For each oShape in ActiveDocument.Shapes
If oShape.TextFrame.HasText Then
oShape.TextFrame.TextRange.Font.Name = "My new font"
End If
Next oShape
 
J

Jean-Guy Marcil

Santa Claus was telling us:
Santa Claus nous racontait que :
Hi,

I'm wanting to create a macro to change the font in all text boxes
with a document. I'm guessing I need to select each box and change the
properties....one at a time. Each document has different types of
objects (Select All doesnt work).

If any one can help with code so make a simple loop macro, I'd
appreciate it.

Try this (There are two loops in case some of the Textboxes are inline with
the text):

Dim myShape As Shape
Dim myInlineShape As InlineShape

For Each myShape In ActiveDocument.Shapes
With myShape
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Bold = True
End If
End With
Next

For Each myInlineShape In ActiveDocument.InlineShapes
With myShape
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Bold = True
End If
End With
Next



--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
Top