我正在尝试通过对宏的访问来导入数据集。我在打开记录集的行中收到上述错误。努力解决,但没有成功。找到了这个问题(Syntax error in FROM clause Excel VBA),但答案没有解决我的问题。请帮忙。
Sub importAccessdata()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sQRY As String
Dim strFilePath As String
strFilePath = "Path"
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & strFilePath & ";"
sQRY = "select * from tableName"
With rs
.CursorLocation = adUseClient
.Open Source:=sQRY, ActiveConnection:=cnn,CursorType:=adOpenForwardOnly, LockType:=adLockOptimistic, Options:=adCmdText
End With
Application.ScreenUpdating = False
ThisWorkbook.Sheets(1).Range(“A1”).CopyFromRecordset rs
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
Exit Sub
End Sub