vba - 使用 chart.chartstyle = 248 时,如何关闭轴标题中的所有大写字母?

标签 vba excel charts fonts axes

问题

我希望能够有效地取消选中所有大写 Font Properties Dialog Box 的复选框在 Excel 图表轴标签/标题上的 VBA 中。

我试过的

对于 excel,所有大写字母作为字符或字体成员的选项似乎在图表中不可用。

此外,仅使用诸如 Upper、Ucase 或 LCase 之类的东西来更改文本是行不通的。

一些代码

我在构建图表的地方包含了我的代码。您可以在评论中看到我更改全大写属性的一些尝试。在 excel 中使用 vba 与一些类似的东西:

 With newChart
    'If put an if statement to see if name already exists, try catch case would be good too
    .Name = UsrFrm2.titleTxt.Text
    .ChartType = xlXYScatterSmoothNoMarkers
    '.CategoryLabelLevel = xlCategoryLabelLevelCustom

    'using preselected formatting for chart
    .ChartStyle = 248
    .ChartColor = 10

    'Labeling
    .HasTitle = True
    .ChartTitle.Text = Me.titleTxt.Text
    .HasAxis(xlCategory, xlPrimary) = True
    .HasAxis(xlCategory, xlSecondary) = True
    .HasAxis(xlValue, xlPrimary) = True
    .HasAxis(xlValue, xlSecondary) = True
    .Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
    '.Axes(xlCategory, xlSecondary).CategoryType = xlAutomatic
    .Axes(xlCategory, xlPrimary).HasTitle = True
    '.Axes(xlCategory, xlSecondary).HasTitle = True
    '.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Loss Tangent (tand)"
    .HasLegend = True
    '.Axes(xlCategory, xlPrimary).MinimumScale = 1000000
   ' .Axes(xlCategory, xlPrimary).MaxiumScale = 1800000000
End With

或类似这样的东西:
With newChart
    'trying to change the axis titles to turn off all caps. I cannot figure out how at the moment, will have to do by hand.
        'Plotyy format
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = UsrFrm2.XALabel.Value
        '.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Font.Bold = False
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Font.FontStyle = "Normal"
        '.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Font.Allcaps = False
        '.Axes(xlCategory, xlPrimary).AxisTitle.Font.Allcaps = False
        .Axes(xlCategory, xlPrimary).MinimumScale = UsrFrm2.XSMin.Value
        .Axes(xlCategory, xlPrimary).MaximumScale = UsrFrm2.XSMax.Value
        .Axes(xlCategory, xlPrimary).MajorUnitIsAuto = True
        .Axes(xlCategory, xlPrimary).MinorUnitIsAuto = True
        If Me.X_MHz.Value = True Then
            .Axes(xlCategory, xlPrimary).DisplayUnit = xlCustom
            .Axes(xlCategory, xlPrimary).DisplayUnitCustom = 1000000#
            .Axes(xlCategory, xlPrimary).HasDisplayUnitLabel = True
            .Axes(xlCategory, xlPrimary).DisplayUnitLabel.Caption = "MHz"
        ElseIf Me.X_GHz.Value = True Then
            .Axes(xlCategory, xlPrimary).DisplayUnit = xlCustom
            .Axes(xlCategory, xlPrimary).DisplayUnitCustom = 1000000000#
            .Axes(xlCategory, xlPrimary).HasDisplayUnitLabel = True
            .Axes(xlCategory, xlPrimary).DisplayUnitLabel.Caption = "GHz"
        Else
            .Axes(xlCategory, xlPrimary).DisplayUnit = xlNone
        End If
        .Axes(xlValue, xlPrimary).MinimumScale = UsrFrm2.YSMin.Value
        .Axes(xlValue, xlPrimary).MaximumScale = UsrFrm2.YSMax.Value
        .Axes(xlValue, xlPrimary).MajorUnitIsAuto = True
        .Axes(xlValue, xlPrimary).MinorUnitIsAuto = True
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).TickLabels.NumberFormat = "General"
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Font.FontStyle = "Normal"
End With

请提出建议。



做或不做,没有尝试——尤达,绝地大师

最佳答案

Chart s 不是 Excel单独但跨所有办公应用程序。所以他们的对象也不是原生的Excel对象。 Allcaps , Smallcaps , ... 是 Font2 的成员目的。 https://msdn.microsoft.com/en-us/library/office/ff863038%28v=office.14%29.aspx

获取 Font2对象有时有点棘手。

假设我们有以下图表:

enter image description here

那么下面的VBA应该做:

Sub test()

 Dim oChart As Chart
 Dim oFont2 As Font2

 Set oChart = ActiveChart

 With oChart
  Set oFont2 = .Axes(xlCategory, xlPrimary).AxisTitle.Format.TextFrame2.TextRange.Font
  oFont2.Allcaps = msoTrue
  oFont2.Allcaps = msoFalse
  oFont2.Smallcaps = msoTrue
  oFont2.Smallcaps = msoFalse

 End With

End Sub

关于vba - 使用 chart.chartstyle = 248 时,如何关闭轴标题中的所有大写字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34773273/

相关文章:

excel - 字典对象函数存在将不存在的键添加到字典中

ms-access - 特殊的列表框。重新查询视觉错误

vba - 有没有办法在VBA中将算术和逻辑运算符作为方法参数传递?

excel - 为什么此代码会影响 C 列中的单元格?

javascript - AngularJS 谷歌图表 : ChartRangeFilter

excel - 使用带有六个条件的图标集的条件格式

vba - 在单独的工作表上打印工作表名称

javascript - 在 Office 加载项中启用扩展错误日志记录(查看错误对象的完整说明)

java - JFreechart - XY Step Chart 范围和精度问题

javascript - 无法在 Highcharts 上添加漂亮的阴影