我在Access VBA中使用代码控制Excel,首先将Access中的数据传送过去,然后新建一sheet,并改名为"Chart",然后根据传送过去的数据画图,但是画图结束后,我怎么也没法把进程中的excel.exe关闭,如果不画图,仅传送数据,然后增加新sheet并改名,就没有这个问题。不知道为什么!特来求助,可否有高手指点迷津?
代码如下:
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Sheets
Dim SaveFilePath
Dim MyChart As ChartDoCmd.SetWarnings False
SaveFilePath = xlApp.GetSaveAsFilename("", "97-2003 Excel 文件 (*.xls), *.xls", , "请选择导出文件名称及路径...")If SaveFilePath = False Then
MsgBox "用户取消了操作!"
Exit SubDoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Data_1“, SaveFilePathSet xlBook = xlApp.Workbooks.Open(SaveFilePath)
xlBook.Worksheets.Add
xlBook.Sheets("Sheet1").Select
xlBook.Sheets("Sheet1").Name = "Chart"
'下面这段画图,如果去掉,那么这个过程运行结束后,进程中就不会有Excel.exe文件了.求助高手~
Set MyChart = xlBook.Sheets("Chart").Shapes.AddChart(xlLine, 0, 0, 347, 157).Chart
MyChart.SetSourceData Source:=Sheets("Data_1"Cells
MyChart.HasTitle = True
MyChart.ChartTitle.Characters.Text = Sheets("Data_1").Range("A1").Value
MyChart.SetElement (msoElementLegendBottom)
MyChart.PlotBy = xlColumnsSet MyChart = Nothing
xlBook.Close True
Set xlBook = Nothing
xlApp.Quit
Set xlApp = NothingDoCmd.SetWarnings True
如有高手帮助,感激不尽啊!
本人新到,分不多,大家海涵啊~
代码如下:
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Sheets
Dim SaveFilePath
Dim MyChart As ChartDoCmd.SetWarnings False
SaveFilePath = xlApp.GetSaveAsFilename("", "97-2003 Excel 文件 (*.xls), *.xls", , "请选择导出文件名称及路径...")If SaveFilePath = False Then
MsgBox "用户取消了操作!"
Exit SubDoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Data_1“, SaveFilePathSet xlBook = xlApp.Workbooks.Open(SaveFilePath)
xlBook.Worksheets.Add
xlBook.Sheets("Sheet1").Select
xlBook.Sheets("Sheet1").Name = "Chart"
'下面这段画图,如果去掉,那么这个过程运行结束后,进程中就不会有Excel.exe文件了.求助高手~
Set MyChart = xlBook.Sheets("Chart").Shapes.AddChart(xlLine, 0, 0, 347, 157).Chart
MyChart.SetSourceData Source:=Sheets("Data_1"Cells
MyChart.HasTitle = True
MyChart.ChartTitle.Characters.Text = Sheets("Data_1").Range("A1").Value
MyChart.SetElement (msoElementLegendBottom)
MyChart.PlotBy = xlColumnsSet MyChart = Nothing
xlBook.Close True
Set xlBook = Nothing
xlApp.Quit
Set xlApp = NothingDoCmd.SetWarnings True
如有高手帮助,感激不尽啊!
本人新到,分不多,大家海涵啊~
xlBook.Close True 也许写的短了些
写成xlBook.Close savechanges:=True
你就能看懂了吧?
呵呵 保存了 就是无法退出 5555
.
.xlBook.Close True
xlApp.Quit
Set MyChart = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
.