Created
May 18, 2017 13:24
-
-
Save nattybear/c2993c5bbf366de8d4edf15b5b086541 to your computer and use it in GitHub Desktop.
vba excel ADO programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub sbADOExample() | |
Dim sSQLQry As String | |
Dim Conn As New ADODB.Connection | |
Dim mrs As New ADODB.Recordset | |
dim DBPath As String, sconnect As String | |
DBPath = ThisWorkbook.FullName | |
sconnect = "Provider=MSDASQL.1;DSN=Excel Files;DBQ=" & DBPath & ";HDR=Yes';" | |
Conn.Open sconnect | |
sSQLString = "SELECT * From [Sheet1$]" | |
mrs.Open sSQLString, Conn | |
Sheet2.Range("A2").CopyFromRecordset mrs | |
mrs.Close | |
Conn.Close | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment