无法找到可安装的ISAM Excel 2010

时间:2014-07-20 19:44:44

标签: excel vba ms-access excel-vba excel-2010

我在Excel 2010中有这个子应该从Access 2010中复制到表中。当我尝试运行代码时,它给了我一个'找不到可安装的ISAM'。当我调试时,它会突出显示objDB.Execute。

Private Sub btnGetData_Click()

Unload ParameterMenu
formWait.Show

'Save workbook
ActiveWorkbook.Save

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

strExcelFile = "X:\Form.xlsm"
strWorksheet = "RawDates"
strDB = "X:\Tables.accdb"
strTable = "Dates"

Set objDB = OpenDatabase(strDB)

objDB.Execute _ 'Error occurs here.
  "SELECT * INTO [Excel 14.0;DATABASE=" & strExcelFile & _
   "].[" & strWorksheet & "] FROM " & "[" & strTable & "]"

objDB.Close
Set objDB = Nothing

Unload formWait
FinishDialog.Show

End Sub

我对VBA没有过多的经验,所以非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

正确的格式是'Excel 12.0 Macro'而不是'Excel 14.0':

objDB.Execute _ 'Error occurs here.
  "SELECT * INTO [Excel 12.0 Macro;DATABASE=" & strExcelFile & _
   "].[" & strWorksheet & "] FROM " & "[" & strTable & "]"

编辑:

或许尝试使用ADO:

Private Sub btnGetData_Click()

Unload ParameterMenu
formWait.Show

'Save workbook
ActiveWorkbook.Save

Dim strExcelFile As String
Dim strWorksheet As String
Dim strDB As String
Dim strTable As String
Dim objDB As Object
Dim rs As Object

strExcelFile = "X:\Form.xlsm"
strWorksheet = "RawDates"
strDB = "X:\Tables.accdb"
strTable = "Dates"

Set objDB = CreateObject("ADODB.Connection")
With objDB
    .Provider = "Microsoft.ACE.OLEDB.12.0"
      .ConnectionString = "Data Source=" & strDB & ";"
      .Open
   End With

Set rs = CreateObject("ADODB.Recordset")

rs.Open "SELECT * FROM " & "[" & strTable & "]", objDB, 3, 1, 1

If Not rs.EOF Then _
ThisWorkbook.Worksheets(strWorksheet).Cells(Rows.Count, "A").End(xlUp).Offset(1).CopyFromRecordset rs

rs.Close
objDB.Close
Set objDB = Nothing

Unload formWait
FinishDialog.Show

End Sub