Excel VBA中自动写入图表的标题

时间:2015-11-17 13:07:16

标签: excel-vba charts vba excel

我尝试在给定的脚本中添加一些命令,以便自动更新图表的标题(图表是由Scott Holtzman提供的相同脚本生成的)。 我的问题: 1.如何使用给定变量更新文本以逃避引号(我已经读过这可以使用双引号""我""但它不起作用) 2.可以写希腊字符以及如何编写? 3.可以用索引或小写字母或下标来书写吗? 4.如何更改轴标签?我已经定义了两个,但我只改变了y轴而不是x轴。

这是我的剧本(由Scott Holtzman提供)以及我正在尝试做的评论:

    Sub MakeCharts()

    Dim ws As Worksheet
    Set ws = Sheets("Tabelle1")
    Dim dthArray() As Variant
    Dim kxArray() As Variant
    Dim text1 As String
    Dim text2 As String
    Dim x As Integer
    Dim y As Integer
    Dim i As Integer
    Dim j As Integer

    i = 1
    j = 1

' Strings for the charts'titles:
    dthArray() = Array("0", "0,5", "1", "5", "10")
    kxArray() = Array("0", "0,01", "1", "5")

    For y = 1 To 259 Step 65
    For x = 1 To 259 Step 13

        ws.Shapes.AddChart.Select

        With ActiveChart

            .ChartType = xlXYScatterSmoothNoMarkers

            Dim k As Integer

            For k = 1 To 13

                .SeriesCollection.NewSeries
                .SeriesCollection(k).Name = ws.Cells(x, k + 1)
                .SeriesCollection(k).XValues = ws.Range(ws.Cells(x + 1, k + 1), ws.Cells(x + 11, k + 1))
                .SeriesCollection(k).Values = ws.Range(ws.Cells(x + 1, 1), ws.Cells(x + 11, 1))
                .HasTitle = True


            Next

            .ApplyLayout (1)

            Dim sName As String
            sName = Replace(.Name, ws.Name & " ", "")
            'Updating String for chart's title
            text1 = dthArray(i)
            text2 = kxArray(j)

            ' Write chart's title
            .ChartTitle.Text = "dth=""text1""" & "  " & "dx = ""text2"""
            'sigma should be in greek and t as subscript
            .Axes(xlValue, xlPrimary).AxisTitle.Text = "sigmat/a"
            .Axes(xlValue, xlPrimary).AxisTitle.Text = "eta=y/H"

        End With

        With ActiveSheet.Shapes(sName)
            .IncrementLeft 300
            .IncrementTop x * 20
        End With
    i = i + 1
    Next
    j = j + 1
    Next
    End Sub

有什么建议吗?

0 个答案:

没有答案