Importare tabella Access da Excel

ges

Excel/VBA Expert
Amministratore
21 Giugno 2015
29.532
2.465
Como
2011MAC 365WIN
1.009
Visual Basic:
Sub Copia_Tabella_Access_to_Excel()
    Dim cn As Object
    Dim rs As Object
    Dim i As Integer
    Dim Conn As String
    Dim nameTable As String
    Set cn = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    Cells.Clear
    nameTable = "Tabella1" '<<NOME TABELLA
    Conn = "Provider = Microsoft.ACE.OLEDB.12.0; Data Source=" & _
        "C:\Users\ges\Desktop\ESEMPIO.accdb;" '<<== PERCORSO DA CAMBIARE
    cn.Open Conn
    rs.Open Source:=nameTable, ActiveConnection:=cn, CursorType:=1, LockType:=3
    For i = 0 To rs.Fields.Count - 1
        Cells(1, i + 1) = rs.Fields(i).Name
    Next i
    Range("A2").CopyFromRecordset rs
End Sub
 
  • Like
Reactions: Rubik72

Sostieni ForumExcel

Aiutaci a sostenere le spese e a mantenere online la community attraverso una libera donazione!