开发者

Reduce Font Size by 1 Step in VBA

Is there a simple way to reduce the Font Size in Word / Excel etc by 1 step in VBA?

So, say if my Font size was 48 could I reduce it to 36, easily, as per the 开发者_运维技巧Font drop down in the standard Word 2007 Font group, rather than reducing the font size by 12 - I will not know what the next font size down is...

So rather than setting Font Size explicitly by float :

MyText.Font.Size = 36;

could I do something like :

MyText.Font.Size -= Reduce by 1 step;....  forgive the pseudo code!


For Excel, you can check the Font Size combobox on the Formatting toolbar. That's 2003 stuff and I think it will still work in 2007 and beyond, but I don't have it available to test.

Sub FontShrink(rng As Range)

    Dim i As Long
    Dim ctl As CommandBarComboBox

    Set ctl = Application.CommandBars("Formatting").Controls("Font Size:")

    If rng.Font.Size > CDbl(ctl.List(ctl.ListCount)) Then
        'if it's bigger than the biggest, make it the biggest
        rng.Font.Size = ctl.List(ctl.ListCount)
    Else
        For i = ctl.ListCount To 2 Step -1
            If rng.Font.Size > CDbl(ctl.List(i)) Then
                rng.Font.Size = CDbl(ctl.List(i))
                Exit For
            ElseIf rng.Font.Size = CDbl(ctl.List(i)) Then
                rng.Font.Size = CDbl(ctl.List(i - 1))
                Exit For
            End If
        Next i
    End If
End Sub


Use the Font object's Shrink method:

MyText.Font.Shrink

The opposite is MyText.Font.Grow.


You can Grow and Shrink fonts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜