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

时间:2016-01-13 17:33:18

标签: vba excel-vba charts fonts axes

问题

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

我尝试了什么

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

此外,仅使用Upper,Ucase或LCase等内容更改文本不起作用。

一些代码

我已将代码包含在构建图表的位置。您可以在评论中看到我尝试更改allcaps属性的一些尝试。在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

建议请。

做或不做,没有尝试--Yoda,Jedi Master

1 个答案:

答案 0 :(得分:0)

Chart不是Excel,而是所有办公应用程序。所以他们的对象也不是本地Excel对象。 AllcapsSmallcaps,...是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