VBA在Excel中画折线图
Option Explicit
Dim Appxls As New Application
Dim WorkBook As WorkBook
Dim AppSheet As Worksheet
Dim PathName As String
Private Sub Command1_Click()
Dim i As Integer
Randomize
Me.CommonDialog1.Filter = "*.xls|*.xls "
Me.CommonDialog1.ShowOpen
PathName = Me.CommonDialog1.FileName
Set WorkBook = Appxls.Workbooks.Open(PathName)
Set AppSheet = WorkBook.Worksheets( "sheet1 ")
For i = 1 To 4
AppSheet.Cells(i, "A ") = CInt(Rnd * 200)
Next
For i = 1 To 4
AppSheet.Cells(i, "B ") = CInt(Rnd * 100)
Next
For i = 1 To 4
AppSheet.Cells(i, "C ") = CInt(Rnd * 100)
Next
Dim x As Chart 'Create an embedded chart on a chart sheet.
Set x = Charts.Add
x.ChartType = xlLine
x.SetSourceData Source:=Sheets( "Sheet1 ").Range( "A1:C4 ")
Set x = x.Location(Where:=xlLocationAsObject, Name:= "Sheet1 ")
' Move chart to new sheet and reset the chart object variable x.
' Set x = x.Location(Where:=xlLocationAsNewSheet, Name:= "Chart1 ")
' Move chart to back to the chart sheet.
End Sub
Private Sub Form_Load()
Me.Show
Set Appxls = Excel.Application
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
WorkBook.Save 'save file(*.xls)
AppSheet.Application.Quit 'close EXCEL.EXE in Windows
Set AppSheet = Nothing
Set WorkBook = Nothing
'Appxls.Quit
Set Appxls = Nothing
End Sub
因为数据是在A1到C4这个矩形范围之内 用什么属性控制 以列上的点为基准划线 或者以行上的点为基准划线
举个例子吧:
这样在Excel中画折线图 以A1~A4 这一列上的4个点画一条线
用什么属性可以控制改为A1,B1,C1这一行上的三个点画一条线??????
高手来看看吧!!!!
[解决办法]
x.SetSourceData Source:=Sheets( "Sheet1 ").Range( "A1:C4 "), PlotBy:=xlColumns
按列,xlRows 就是按行了!