关于EXCEL VBA 用ADO连接ACCESS数据库的问题,重谢!
Sub快速与Access创建数据连接()'使用实例文件F_Data.accdbF_Tbl01DimmyCnc1AsStringDimmyCnc2AsStr...
Sub 快速与Access创建数据连接()
'使用实例文件 F_Data.accdb F_Tbl01
Dim myCnc1 As String
Dim myCnc2 As String
Dim myCnc3 As String
Dim myCmd As String
Dim myFileName As String
Dim myTblName As String
Worksheets.Add
myFileName = "F_Data.accdb" '读入文档
myTblName = "F_Tbl01" '读入表
myCnc1 = "ODBC;"
myCnc2 = "DBQ=" & ThisWorkbook.Path & "\" & myFileName & ";"
myCnc3 = "Driver={Microsoft Access Driver (*.accdb)};"
'使用SQL来读入资料
myCmd = "SELECT * FROM " & myTblName
With ActiveSheet.QueryTables.Add _
(Connection:=myCnc1 & myCnc2 & myCnc3, Destination:=Range("A1"))
.CommandText = myCmd
.Refresh BackgroundQuery:=False
End With
End Sub
这段代码哪里里有错误?我运行后提示有错误我是10版本的EXCEL 展开
'使用实例文件 F_Data.accdb F_Tbl01
Dim myCnc1 As String
Dim myCnc2 As String
Dim myCnc3 As String
Dim myCmd As String
Dim myFileName As String
Dim myTblName As String
Worksheets.Add
myFileName = "F_Data.accdb" '读入文档
myTblName = "F_Tbl01" '读入表
myCnc1 = "ODBC;"
myCnc2 = "DBQ=" & ThisWorkbook.Path & "\" & myFileName & ";"
myCnc3 = "Driver={Microsoft Access Driver (*.accdb)};"
'使用SQL来读入资料
myCmd = "SELECT * FROM " & myTblName
With ActiveSheet.QueryTables.Add _
(Connection:=myCnc1 & myCnc2 & myCnc3, Destination:=Range("A1"))
.CommandText = myCmd
.Refresh BackgroundQuery:=False
End With
End Sub
这段代码哪里里有错误?我运行后提示有错误我是10版本的EXCEL 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询