2个回答
展开全部
1. 打开EXCEL表,将其中一个表单取名为“Result",假设你的Access数据库在C:\TEST.accdb;数据库表名为Test01
2. 将下面代码植入宏编辑器中,注意引用Excel控件MS ActiveX object 2.6和DAO 3.6
Sub ReadAccessToExcel()
Set ReadCooisCn = New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim RstX As New ADODB.Recordset
With ReadCooisCn
.Provider = "Microsoft.ACE.OLEDB.12.0;Data source=" _
& "C:\Test.accdb;Persist Security Info=False;"
.Open
End With
Sqlstr = "select * from Table01"
Rst.Open Sqlstr, ReadCooisCn, adOpenKeyset, adLockOptimistic
If Rst.RecordCount > 0 Then
worksheets("Result").cells(1,1).CopyFromRecordset Rst
End If
Rst.Close
Set Rst = Nothing
ReadCooisCn.Close
end Sub
2. 将下面代码植入宏编辑器中,注意引用Excel控件MS ActiveX object 2.6和DAO 3.6
Sub ReadAccessToExcel()
Set ReadCooisCn = New ADODB.Connection
Dim Rst As New ADODB.Recordset
Dim RstX As New ADODB.Recordset
With ReadCooisCn
.Provider = "Microsoft.ACE.OLEDB.12.0;Data source=" _
& "C:\Test.accdb;Persist Security Info=False;"
.Open
End With
Sqlstr = "select * from Table01"
Rst.Open Sqlstr, ReadCooisCn, adOpenKeyset, adLockOptimistic
If Rst.RecordCount > 0 Then
worksheets("Result").cells(1,1).CopyFromRecordset Rst
End If
Rst.Close
Set Rst = Nothing
ReadCooisCn.Close
end Sub
追问
可不可以加一些注释进去呀,让我更好理解。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |