下面我已程序代码做成模块,只要导入必要之参数即可! 此一模块共有四个参数: 1、sSheetName:要导出资料的文件名称 (Sheet name),例如 Sheet1 2、sExcelPath:要导出资料的 Excel 档案路径名称 (Workbook path),例如 C:\book1.xls 3、sAccessTable:要导入的 Access Table 名称,例如 TestTable 4、sAccessDBPath:要导入的 Access 档案路径名称,例如 C:\Test.mdb 在声明中加入以下: Private Sub ExportExcelSheetToAccess(sSheetName As String, sExcelPath As String, sAccessTable As String, sAccessDBPath As String) Dim db As Database Dim rs As Recordset Set db = OpenDatabase(sExcelPath, True, False, "Excel 5.0") Call db.Execute("Select * into [;database=" & sAccessDBPath & "]." & sAccessTable & " FROM [" & sSheetName & "$]") MsgBox "Table exported successfully.", vbInformation, "Yams" End Sub 使用范例如下:將 C:\book1.xls 中的 Sheet1 导入 C:\Test.mdb 成为 TestTable ExportExcelSheetToAccess "Sheet1", "C:\book1.xls", "TestTable", "C:\Test.mdb" |