[Excel] [VBA]如何在图形中画线?

hun*_*m06 5 excel vba graph excel-vba draw

请查看此图片以明确回答我的问题: 在此处输入图片说明

Tim*_*ams 5

Sub Tester()
    Dim s, d

    d = #4/18/2011# * 1 ''a bit of a hack, since I could figure out how to plot a date directly
    With ActiveSheet.ChartObjects("Chart 1").Chart 'adjust to suit

        Set s = .SeriesCollection.NewSeries()
        With s
            .Name = ""
            .XValues = Array(d, d)
            .Values = Array(90, 0)
            .MarkerStyle = xlMarkerStyleNone
            .Border.Color = vbRed
        End With

    End With

End Sub
Run Code Online (Sandbox Code Playgroud)

  • @ hungbm06:啊哈。我只是转载了您的问题。有关解决方案,请参见@Jon Peltier的答案。您必须将图表类型从折线图更改为XY(散点图)图表。通常,我发现XY图表更易于操作,更难以固定。 (2认同)