主题:象charts的方法global失败,为什么
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1) = Text1.Text
xlSheet.Cells(2, 1) = Text2.Text
xlSheet.Cells(3, 1) = Text3.Text
xlSheet.Cells(4, 1) = Text4.Text
xlSheet.Cells(5, 1) = Text5.Text
xlSheet.Cells(6, 1) = Text6.Text
xlApp.Visible = True
charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:A6"), PlotBy:= _
xlColumns
ActiveChart.SeriesCollection(1).Name = "=""水位曲线图"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "水位曲线图"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
ActiveChart.HasLegend = False
ActiveChart.ChartArea.Copy '读取图表到剪贴板
Picture1.Picture = Clipboard.GetData '粘贴数据到图片框
Clipboard.Clear '清除剪贴板数据
xlApp.ActiveWorkbook.Saved = True '放弃存盘
xlApp.Quit '退出整个EXCEL
Set xlApp = Nothing '交还控制给Excel
End Sub
上面是我写的代码,当第一次点击运行时正常,第二次点击运行时出现的错误:对象charts的方法global失败,为什么???
谢谢各位大侠指点!!!
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1) = Text1.Text
xlSheet.Cells(2, 1) = Text2.Text
xlSheet.Cells(3, 1) = Text3.Text
xlSheet.Cells(4, 1) = Text4.Text
xlSheet.Cells(5, 1) = Text5.Text
xlSheet.Cells(6, 1) = Text6.Text
xlApp.Visible = True
charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:A6"), PlotBy:= _
xlColumns
ActiveChart.SeriesCollection(1).Name = "=""水位曲线图"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "水位曲线图"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
ActiveChart.HasLegend = False
ActiveChart.ChartArea.Copy '读取图表到剪贴板
Picture1.Picture = Clipboard.GetData '粘贴数据到图片框
Clipboard.Clear '清除剪贴板数据
xlApp.ActiveWorkbook.Saved = True '放弃存盘
xlApp.Quit '退出整个EXCEL
Set xlApp = Nothing '交还控制给Excel
End Sub
上面是我写的代码,当第一次点击运行时正常,第二次点击运行时出现的错误:对象charts的方法global失败,为什么???
谢谢各位大侠指点!!!