Me.为无效关键字,是要换成相应的坐标行吗?
画折线图 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
= "*.xls|*.xls "
PathName =
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 "), PlotBy:=xlColumns
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