简体   繁体   English

Visual Basic:导出访问 Excel 表 | VBA

[英]Visual Basic : Export Access to Excel Table | VBA

My Project is 45% I Need help to convert to export access data to excel spreadsheet, The "*" is the code im having problem with it, Im Using Visual Studio 2013我的项目是 45% 我需要帮助将访问数据转换为 Excel 电子表格,“*”是我遇到问题的代码,我使用 Visual Studio 2013

Im going to export access 2013 table to excel 2013.我打算将 access 2013 表导出到 excel 2013。

'EXPORTS TABLE IN ACCESS DATABASE TO EXCEL 'ACCESS DATABASE TO EXCEL 中的导出表

    Dim strExcelFile As String
    Dim strWorksheet As String
    Dim strDB As String
    Dim strTable As String
    * Dim objDB As Database

    strExcelFile = "|DataDirectory|\ExportedData.xls"
    strWorksheet = "WorkSheet1"
    strDB = "C:\My Documents\MyDatabase.mdb"
    strTable = "MyTable"

    * objDB = OpenDatabase(strDB)

    If Dir(strExcelFile) <> "" Then Kill(strExcelFile)

    objDB.Execute _
      "SELECT * INTO [Excel 8.0;DATABASE=" & strExcelFile & _
       "].[" & strWorksheet & "] FROM " & "[" & strTable & "]"
    objDB.Close()
    objDB = Nothing

NEW CODE新代码

Having error on acExport, What do you think this variable is used for. acExport 出错,你认为这个变量是干什么用的。

< <

    Dim objDB As Object
    Dim strExcelFile As String
    Dim strWorksheet As String
    Dim strDB As String
    Dim strTable As String
    strExcelFile = "|DataDirectory|\ExportedData.xls"
    strWorksheet = "sheet1"
    strDB = "|DataDirectory|MyDatabase.mdb"
    strTable = "MyTable"

    objDB.OpenCurrentDatabase(strDB)
    objDB.DoCmd.TransferSpreadsheet(acExport, 8, strTable, strExcelFile, True, strWorksheet)

    objDB.CloseCurrentDatabase()
    objDB = Nothing

> >

Set objDB = OpenDatabase(strDB)

为对象类型变量赋值时应该使用 Set

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM