vba 如何更改图表中的所有字体?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22422368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change all fonts in chart?
提问by Lluser
I 'm trying to change font in entire chart. Recorded macro using Shapes collection > Shape object > TextFrame2 (contains text formatting for the specified shape) > TextRange > Font.
我正在尝试更改整个图表中的字体。使用形状集合 > 形状对象 > TextFrame2(包含指定形状的文本格式)> TextRange > 字体录制的宏。
With ActiveSheet.Shapes("Chart 1502").TextFrame2.TextRange.Font
.NameComplexScript = "Arial"
.NameFarEast = "Arial"
.Name = "Arial"
End With
I checked it in documentation and it seems like good way, but when I try run this recorded macto, it throws : Run-time error: '-2147024809 (80070057)':Entered value is out of range(my translation - I have localized version).
我在文档中检查了它,这似乎是个好方法,但是当我尝试运行这个录制的 macto 时,它抛出: 运行时错误:'-2147024809(80070057)':输入的值超出范围(我的翻译 - 我已经本地化版本)。
Error is on this line (especially with TextFrame2)
错误在这一行(尤其是TextFrame2)
With ActiveSheet.Shapes("Chart 1502").TextFrame2.TextRange.Font
Because
因为
set x = ActiveSheet.Shapes("Chart 1502")' is OK
But
但
set x = ActiveSheet.Shapes("Chart 1502").TextFrame2 'throws Run-Time Error
采纳答案by Dmitry Pavliv
Try this one:
试试这个:
Sub test()
Dim x As Shape
Set x = ActiveSheet.Shapes("Chart 1502")
With x.Chart.ChartArea.Format.TextFrame2.TextRange.Font
.NameComplexScript = "Arial"
.NameFarEast = "Arial"
.Name = "Arial"
End With
End Sub
I also suggest to change ActiveSheet.Shapes("Chart 1502")
to something like this: Worksheets("Sheet1").Shapes("Chart 1502")
.
我还建议更改ActiveSheet.Shapes("Chart 1502")
为这样的:Worksheets("Sheet1").Shapes("Chart 1502")
.