关于怎么用VBA导出Access的表
Access的表,可以导出成为Excel的电子表格,但是用VBA怎么实现??求达人
[解决办法]
Sub AC()
Dim cnn As New Connection
Dim rs As New Recordset
Dim sql As String
Dim qx As String
qx = "金牛"
cnn.Open "Provider=Microsoft.Ace.OleDB.12.0;data Source=" & ThisWorkbook.Path & "\数据库.accdb"
sql = "select * from [宏站] where 区域='" & qx & "'"
'('" & qx & "'")括号里这段有点BT,一定要这样写才行。
rs.Open sql, cnn
[a1].CopyFromRecordset rs
End Sub
Sub AC()
Dim cnn As New Connection
Dim rs As New Recordset
Dim sql As String
Dim qx As String
qx = "金牛"
cnn.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & ThisWorkbook.Path & "\数据库.mdb"
sql = "select * from [宏站] where 区域='" & qx & "'"
'('" & qx & "'")括号里这段有点BT,一定要这样写才行。
rs.Open sql, cnn
'复制字段名
For i = 1 To rs.Fields.Count
Cells(1, i) = rs.Fields(i - 1).Name
Next i
'复制全部数据
Range("A2").CopyFromRecordset rs
rs.Close
cnn.Close
End Sub
Sub 远程()
Dim cnn As New Connection
Dim rs As New Recordset
Dim sql As String
Dim qx As String
qx = "金牛"
cnn.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=\\192.168.0.101\\ac\\数据库.mdb "
sql = "select * from [宏站] where 区域='" & qx & "'"
'('" & qx & "'")括号里这段有点BT,一定要这样写才行。
rs.Open sql, cnn
[a1].CopyFromRecordset rs
End Sub