Views

Histats

Vitrine

VBA Excel: Importe dados a partir do MS Access para o MS Excel (Via DAO)

Então, o crossover entre Access e Excel continuam a persistir...

Como posso importar os dados do Access para minhas planilhas Excel?

Implementem o código abaixo...

Sub DAOCopyFromRecordSet(DBFullName As String, TableName As String, FieldName As String, TargetRange As Range)
      ' Exemplo: DAOCopyFromRecordSet "C:\A&A_Folder\DataBase.mdb", "TableName", "FieldName", Range("C1")
 
    Dim db As Database, rs As Recordset
      Dim intColIndex As Integer

   Set TargetRange = TargetRange.Cells(1, 1)
   Set db = OpenDatabase(DBFullName)
   Set rs = db.OpenRecordset(TableName, dbOpenTable) ' Todos os registros.

   For intColIndex = 0 To rs.Fields.Count - 1
          Let TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
   Next

    ' Escreva no Recordset.
   TargetRange.Offset(1, 0).CopyFromRecordset rs

   Set rs = Nothing

      db.Close

   Set db = Nothing
End Sub
André Luiz Bernardes A&A - WORK, DON´T PLAY! http://al-bernardes.sites.uol.com.br/ bernardess@gmail.com

✔ VBA Brazil®

✔ VBA Brazil®
brazilsalesforceeffectiveness@gmail.com
Related Posts Plugin for WordPress, Blogger...
diHITT - Notícias