是否可以自动从导出的Access数据生成Excel中的图形?

时间:2017-07-10 14:55:50

标签: excel vba ms-access access-vba

我在Access中设置了一个数据库(注意我的Access,VBA或excel经验很少,如果我犯了任何愚蠢的错误,那就很抱歉)。我目前的目标是能够将Access中的数据导出到新的Excel工作表中,并在Excel中生成从该数据生成的图表。 IE运行VBA代码,创建一个新的Excel工作表,以及打开该工作表以查看导出的数据以及已根据该数据创建的图表。

现在,我有代码将表从Access导出到Excel

Sub exportToXL()

'goes to ErrorHanlder at bottom
On Error GoTo ErrorHandler

'variable declarations
Dim dbTable As String 'name of table to export
Dim xlWorksheetPath As String 'the file location to create the new Excel workbook in


xlWorksheetPath = CurrentProject.Path 'set the file location, returns name of current file? other cmd can do this more directly(?)

xlWorksheetPath = "Supplier Audit Database Excel Export " & Format(Date, "MM-dd-yyyy") 'establishes the name of the new workbook as "Supplier..." etc + that day's current date

dbTable = "all_data" 'set the name of the table to be exported

'the actual command to export the table
'TransferType -- the type of transfer you want to make
'   acExport -- data is exported
'SpreadsheetType -- type of spreadsheet (filetype) to import to
'   acSpreadsheetTypeExcel12Xml -- Microsoft Excel 2010/2013/2016 XML format (.xlsx, .xlsm, .xlsb)
'TableName
'FileName
'HasFieldNames -- when data is exported to Excel, the first row in the worksheet will have the Access field names (column headers exported too basically)
DoCmd.TransferSpreadsheet transfertype:=acExport, spreadsheettype:=acSpreadsheetTypeExcel12Xml, tablename:=dbTable, FileName:=xlWorksheetPath, hasfieldnames:=True
'this seems to create the new EXcel file in the directory this current database is currently stored in for the specific user

'Exits the sub
ErrorHandlerExit:

    Exit Sub

'outputs error in message box, goes to ErrorHandlerExit
ErrorHandler:

    MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description

    Resume ErrorHandlerExit


End Sub

但我无法弄清楚如何从Excel端的表中生成图表。

有人知道我怎么能做到这一点吗?这甚至可能在我正在做的事情中吗?

提前致谢

0 个答案:

没有答案