创建一个双折线图标题,并使第二行的字体较小

Create a two line chart Title, and make the second line a smaller font size

我想使用 VBA 生成一个双折线图标题,但是我希望第二行的大小为 8,顶行更大,比如 12 磅。 这可以在 Excel 2008 年完成吗?

  Sub CreateChart()
    Dim rng As Range
    Dim cht As Object

    Dim strTitle As String
    strTitle = "CHINA - Currently Infected against  USA, Spain, Germany" & vbCrLf & _
                   "by FRANCK FERRANTE - MegapixelRealestate.com (updated 10-April)"

    Set rng = ActiveSheet.Range("A1:E81")

    Set cht = ActiveSheet.ChartObjects.Add(Top:=120, Left:=550, Width:=460, Height:=260)

    cht.Chart.SetSourceData Source:=rng
    cht.Chart.ChartType = xlColumnClustered
    cht.Chart.HasTitle = True

    With cht.Chart

        .ChartTitle.Text = strTitle
        With .ChartTitle.Characters(1, InStr(strTitle, vbCrLf) - 1)
            .Font.Size = 8
            .Font.Color = vbRed
        End With

        With .ChartTitle.Characters(InStr(strTitle, vbCrLf) + 1, Len(strTitle))
            .Font.Size = 12
            .Font.Color = vbBlue
        End With
    End With

    cht.Chart.ChartGroups(1).GapWidth = 8
    cht.Chart.ChartGroups(1).Overlap = 100
    cht.Chart.ChartTitle.Font.Size = 12


    With cht.Chart.PlotArea.Format.Fill

        .Visible = False
  'add fill color to Plot Area
        .Visible = True
        .Solid

        .ForeColor.RGB = RGB(253, 234, 218)
        .Transparency = 0.6

    End With


    With cht.Chart.ChartArea.Format.Fill

        .Visible = False

        .Visible = True

        .Solid

        .ForeColor.RGB = RGB(255, 255, 255)

        .Transparency = 0.2

    End With


    With cht.Chart.PlotArea.Select
        Selection.Left = 5
        Selection.Top = 40
        Selection.Width = 400
        Selection.Height = 205

    End With

'move chart to sheet 1

    ActiveSheet.ChartObjects(1).Cut
    Sheets("Sheet1").Select
    Range("F16").Select
    ActiveSheet.Paste

End Sub

以上是我正在使用的代码,需要您的帮助。

请试试这段代码:

Private Sub ChartTitleDifferentLineFont()
 Dim shCh As Chart, strTitle As String
 strTitle = "Test" & vbCrLf & "Title"

 Set shCh = ActiveChart
 With shCh
    .HasTitle = True
    .ChartTitle.Select
    .ChartTitle.text = strTitle
     With .ChartTitle.Characters(1, InStr(strTitle, vbCrLf) - 1)
        .Font.Size = 12
        .Font.Color = vbRed
     End With
    With .ChartTitle.Characters(InStr(strTitle, vbCrLf) + 1, Len(strTitle))
        .Font.Size = 8
        .Font.Color = vbBlue
    End With
 End With
End Sub