Hi Andreas,
Recursively halving the range until you don't get wdUndefined should be
pretty fast... See macros below.
Hope I got the logic right... you should run a few tests.
Regards,
Klaus
Sub SelectionFontSize()
' select some text and run this macro
Dim rng As Range
Dim min As Single
Dim max As Single
' smallest possible size:
max = 1
' largest possible size:
min = 1638
Set rng = Selection.Range.Duplicate
Call MinMaxFontSize(rng, min, max)
MsgBox min & "/" & max, , "min/max font size"
End Sub
Sub MinMaxFontSize(rng As Range, min As Single, max As Single)
Dim myFontSize As Single
Dim rng1 As Range
Dim rng2 As Range
myFontSize = rng.Font.Size
If rng.Font.Size = wdUndefined Then
Set rng1 = rng.Duplicate
Set rng2 = rng.Duplicate
rng1.End = rng.Start + Int(0.5 * (rng.End - rng.Start))
rng2.Start = rng1.End + 1
Call MinMaxFontSize(rng1, min, max)
Call MinMaxFontSize(rng2, min, max)
Else
If myFontSize < min Then
min = myFontSize
Else
If myFontSize > max Then
max = myFontSize
End If
End If
End If
End Sub
Klaus Linke - 04 Nov 2004 19:53 GMT
I knew I'd blow this!
Change
If myFontSize < min Then
min = myFontSize
Else
If myFontSize > max Then
max = myFontSize
End If
End If
to
If myFontSize < min Then
min = myFontSize
End If
If myFontSize > max Then
max = myFontSize
End If
BTW, another thing you could try is to collapse the selection to the start,
then use
Selection.SelectCurrentFont
You now can be sure that you don't get wdUndefined for the font size.
Collapse to the end, rinse and repeat, until you are at the end of the
range.
Or get the size of the first character, and use "Edit > Find" for this font
size. Then collapse to the end, rinse and repeat.
The last method should also be pretty fast.
"Find" matches one paragraph at a time whereas the recursive macro can get
the size for several paragraphs in one go.
OTOH, the recursive macro may get wdUndefined quite often, before it
determines the real font size.
Regards,
Klaus