从Access到Excel示例。
Dim cn As Object
Dim rs As Object
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim s As String
Dim i As Integer, j As Integer
''Access database
strFile = "z:\docs\dbfrom.mdb"
''This is the Jet 4 connection string, you can get more
''here : http://www.connectionstrings.com/excel
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";"
''Late binding, so no reference is needed
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
'Rough idea
intID = Sheet1.[A1]
strSQL = "SELECT * " _
& "FROM Test " _
& "WHERE ID = " & intID
rs.Open strSQL, cn, 3, 3
''Pick a suitable empty worksheet for the results
Worksheets("Sheet3").Cells(2, 1).CopyFromRecordset rs
''Tidy up
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
这是可能的。你现在怎么做? – JimmyPena
目前,我在每天结束时运行Access查询来更新表格。 Excel文件链接到Access中的该表以引入上面的三列。他们可以使用Excel中的过滤器,但速度很慢。 – user955289
这不仅是可能的,ADO也不是特别困难:http://support.microsoft.com/kb/257819,还有一些在StackOverflow上发布的示例。您可以使用命令对象和参数来确保安全。 – Fionnuala