Home > Software engineering >  Office 2016 professional enhanced version of VBA for excel data source query data
Office 2016 professional enhanced version of VBA for excel data source query data

Time:11-22

Environment: win32 + office 2016 professional enhanced version
Reference: Microsoft Excel 16.0 Object Library, Microsoft ActiveX Data Objects 6.1 Libray and Microsoft ActiveX Data ObjectsRrecordset 6.0 Libray
Procedure is as follows:
Private Sub CommandButton1_Click ()
Dim Con As New ADODB. Connection
Dim strCon As String
Dim strSQL As String
Dim the rs As ADODB. You 'set the Recordset
Dim I
StrCon="Provider=Microsoft. ACE. The OLEDB. 16.0. Data Source=D: \ 001 basic Data \ subsidiary business combing \ TEMPEXCEL XLSM; Extended Properties=16.0 Excel macro; HDR=Yes; IMEX=0 "
Con. Open strCon
StrSQL="SELECT distinct * FROM [Sheet1 $D1: F $50]"
Set the rs=Con. The Execute (strSQL)
For I=1 To rs. Fields. The Count - 1 'individually field
Cells (3, I + 3)=rs. Fields (I). The Name 'take the field Name "placed in cell (3, 3)
Next I
Range (" c9 "). CopyFromRecordset rs
Rs. Close
Con. Close
Set the rs=Nothing
The Set of Con=Nothing
End sub

Debugging error: could not find the ISAM installable
Error: Con. Open strCon

CodePudding user response:

Data Source at the back of the path to quotes
Extended Properties behind the macro words don't know if there is something wrong

CodePudding user response:

Syntax error, it should be: "the Provider=Microsoft. ACE. The OLEDB. 16.0; Data Source="" D: \ 001 basic Data \ subsidiary business combing \ TEMPEXCEL XLSM" "; Extended Properties="" Excel macro 16.0; HDR=Yes; IMEX=0 "" quotes
Prev:VBA
Next:postman
  •  Tags:  
  • VBA
  • Related