[英]Reduce Font Size by 1 Step in VBA
有没有一种简单的方法可以在 VBA 中将 Word / Excel 等中的字体大小减少 1 步?
所以,假设我的字体大小是 48,我可以根据标准 Word 2007 字体组中的字体下拉菜单轻松地将其减小到 36,而不是将字体大小减小 12 - 我不知道下一个字体大小是多少下来是...
因此,不要通过浮点数显式设置字体大小:
MyText.Font.Size = 36;
我可以做类似的事情:
MyText.Font.Size -= Reduce by 1 step;.... forgive the pseudo code!
对于 Excel,您可以检查格式工具栏上的字体大小 combobox。 那是 2003 年的东西,我认为它在 2007 年及以后仍然可以使用,但我没有它可供测试。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.