[英]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.