Skip to content

Instantly share code, notes, and snippets.

@nattybear
Created May 18, 2017 13:24
Show Gist options
  • Save nattybear/c2993c5bbf366de8d4edf15b5b086541 to your computer and use it in GitHub Desktop.
Save nattybear/c2993c5bbf366de8d4edf15b5b086541 to your computer and use it in GitHub Desktop.
vba excel ADO programming
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