问题描述
我希望我不是在错误的地方,自从我登录后已经有一段时间了。
大家好,我正在开发一个简单的VBA项目。我有一个MS访问数据库,我想在Excel上查看其内容。我能够连接到数据库并获取表格的内容。
以确保我获得表格的内容,我能够使用消息框显示我需要的数据,我看到它正确地取出它们
现在我的问题是,我如何将数据放入excel单元格?
下面是获取数据的代码,假设与DB的连接正常。
'设置ADO Recordset对象:
设置adoRecSet =新ADODB.Recordset
'打开名为Provider的表:
strTable =providertbl
adoRecSet.Open来源:= strTable,ActiveConnection:= connDB,CursorType:= adOpenStatic,LockType:= adLockPessimistic
For i = 0 to adoRecSet.Fields.Count - 1
'get field / column name:
MsgBox adoRecSet.Fields( i).Name
adoRecSet.MoveFirst
Do not not adoRecSet.EOF
'获取记录值:
MsgBox adoRecSet.Fields(i).Value
adoRecSet.MoveNext
Loop
Next i
有人会想知道如何将数据放入excel单元格吗?非常感谢。
I hope i'm not on the wrong place, been a while since i logged in.
Hi everyone, i am working on a simple VBA project. i have an MS access database and i want to view its content on excel. i was able to connect to the database and fetch the content of the table.
to make sure that i am getting the table's content, i was able to use message box to show the data that i needed and i see it correctly fetches them
now my problem is, how do i put the data in an excel cell?
below is the code to fetch the data, assuming that connection to DB is OK.
'Set the ADO Recordset object:
Set adoRecSet = New ADODB.Recordset
'Opening the table named Provider:
strTable = "providertbl"
adoRecSet.Open Source:=strTable, ActiveConnection:=connDB, CursorType:=adOpenStatic, LockType:=adLockPessimistic
For i = 0 To adoRecSet.Fields.Count - 1
'get field / column name:
MsgBox adoRecSet.Fields(i).Name
adoRecSet.MoveFirst
Do While Not adoRecSet.EOF
'get record value:
MsgBox adoRecSet.Fields(i).Value
adoRecSet.MoveNext
Loop
Next i
can someone give an idea how to do put the data in a excel cell? thanks a lot.
这篇关于获取MS Access数据并在Excel上查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!