Getting and setting font size of found text

B

BP

Dear Friends,

I'm trying to write a macro that reduces the size of each
chunk of text formatted with a specific font to a percentage
of the font size of that chunk, i.e. if a certain chunk of
text is 18pt Arial it should become 10.5pt Arial (yes I know
18*0.6 = 10.8, but Word apparently rounds down to the
nearest half point, which is good enough for me), if another
chunk is 12pt Arial it should become 7pt (~7.2) and so on.
The macro I've written is as follows:

* Sub Smaller()
* With Selection.Find
* .ClearFormatting
* .Font.Name = "Arial"
* mySize = Selection.Font.Size
* With .Replacement
* .Font.Size = mySize * 0.6
* End With
* .Execute Replace:=wdReplaceAll, Forward:=True, _
* Wrap:=wdFindContinue
* End With
* End Sub

It does wrong in that it sets all text formatted in Arial to
..6 times the size of the first character in the document --
regardless of what font it is. Can someone tell me how to
correct this?

TIA,

/BP
 
G

Greg Maxey

Try:
Sub Scratchmacro()
Dim oRng As Word.Range
Dim pSize As Double
Set oRng = ActiveDocument.Range
With oRng.Find
.Font.Name = "Arial"
While .Execute
With oRng
pSize = oRng.Font.Size
pSize = pSize * 0.6
oRng.Font.Size = pSize
.Collapse wdCollapseEnd
End With
Wend
End With

End Sub
 

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