Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub importAccessdata()
- Dim cnn As ADODB.Connection
- Dim rs As ADODB.Recordset
- Dim sQRY As String
- Dim strFilePath As String
- strFilePath = "Filename" 'Set Filename to be the Access database you are using, include the full path
- Set cnn = New ADODB.Connection
- Set rs = New ADODB.Recordset
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=" & strFilePath & ";"
- sQRY = "SELECT * FROM Object" 'Replace Object with your database object name (table or query)
- rs.CursorLocation = adUseClient
- rs.Open sQRY, cnn, adOpenStatic, adLockReadOnly
- Application.ScreenUpdating = False
- Sheet1.Range("A1").CopyFromRecordset rs
- rs.Close
- Set rs = Nothing
- cnn.Close
- Set cnn = Nothing
- Exit Sub
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement