Excel captures access data through scripts

Source: Internet
Author: User

Open excel, right-click "sheet1", select "view code" at the bottom of the menu, and copy the script to the vbscript editor, click "tools-Reference", select Microsoft ActiveX Date Objects 2.8, and click "OK". Then run the code.

Public Function daadfa ()
'First reference ado --------- click "tool-reference" and then find Microsoft ActiveX Date Objects X. X Library

Dim conn As New ADODB. Connection, connstr As String, db As String, rs As New ADODB. Recordset, I As Long, rows As Long
Db = "C: \ 1 \ db. mdb"
Connstr = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & db
On Error Resume Next
Conn. Open connstr
Rs. Open "select * from userinfo", conn, 1, 3
If rs. EOF Or rs. BOF Then
MsgBox "It is nothing ."
Else
'If the username value in access is equal to Seven, put the userid value of the original record in the 10th rows and 10th columns of the excel table.
'If rs ("username") = "Seven" Then
'Worksheets ("sheet1"). Cells (10, 10). Value = rs ("userid ")
'End If

'Capture the criteria of no column in access using the operator and store them in the first row of the sheet 1 worksheet in excel.
Rows = 1
For I = 0 To rs. Fields. Count-1
Worksheets ("sheet1"). Cells (1, rows). Value = rs. Fields (I). Name
Next I

'Capture the numbers corresponding to each column in the access using the cyclical method.
Do Until rs. EOF
For I = 0 To rs. Fields. Count-1
Worksheets ("sheet1"). Cells (I + 2, rows). Value = rs (I)
Next I
Rows = rows + 1
Rs. MoveNext
Loop
End If

End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.