我似乎无法弄清楚以下陈述中的from子句有什么问题:
INSERT INTO [tblFYPNameStudents] ([FypID], [Title], [StudentName]) SELECT * FROM [Excel 12.0;HDR=YES;Data Source='C:\Users\Lenovo\Documents\testwb.xlsm'].Sheet1$A5:C26
导致错误80040e14,From Clause'
中的语法错误代码如下:(我是VBA的新手以及所有这些,但我无法弄清楚出了什么问题。我认为这与我指定的from子句中的位有关excel和数据源)
Sub AccImport(tblName As String, _
hasf As Boolean, _
tblrange As String)
Set cn = CreateObject("ADODB.Connection")
sDB_Path = ActiveWorkbook.Path & Application.PathSeparator & TARGET_DB
dbWb = Application.ActiveWorkbook.FullName
dbWs = Application.ActiveSheet.Name
scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sDB_Path
strFile = Workbooks(1).FullName
dsh = tblrange
cn.Open scn
ssql = "INSERT INTO " & tblName
MsgBox ssql
ssql = ssql & "SELECT * FROM [Excel 12.0;HDR=YES;Data Source='" & dbWb & "']." & dsh
MsgBox ssql
cn.Execute ssql
End Sub
答案 0 :(得分:0)
你的语法不太正确 - 应该是:
ssql = ssql & "SELECT * FROM [Excel 12.0;HDR=YES;Database=" & dbWb & "].[" & dsh & "]"