Skip to content
ELECTRONICS ENGINEERINGelectronics-engineering.com
Access

How to Export Data from Access to Excel

A very simple example of exporting data from Access to Excel, built as a small VBA tool. Dim rs As DAO.Recordset Dim ex As Excel.Application Dim wb As Excel.Workbook Dim…

https://www.electronics-engineering.com/en/how-to-export-data-from-access-to-excel/

Was this page useful? Rate it:
average 4.0 from 1 rating

A very simple example of exporting data from Access to Excel, built as a small VBA tool

Dim rs As DAO.Recordset
Dim ex As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim i As Integer

'apre excel
Set ex = New Excel.Application
ex.Visible = True 'metti false se non vuoi vedere excel a video

'apre il file xls
Set wb = ex.Workbooks.Open("miofile.xls")

'seleziona il foglio 1
Set ws = wb.Worksheets(1)

'apre un recordset con la tabella da esportare
Set rs = CurrentDb.OpenRecordset("Tabella", DAO.dbOpenDynaset)

'loop sui record
Do Until rs.EOF
'aggiorna un contatore
i = i + 1

'imposta la colonna A e B per la riga = i
ws.Cells(i, 1) = rs("ID")
ws.Cells(i, 2) = rs("Descrizione")

'prossimo record
rs.MoveNext
Loop

'chiude recordset
rs.Close

'salva file
wb.Save

'chiude file
wb.Close

'esce da excel
ex.Quit

'cancella variabili oggetto
Set rs = Nothing
Set ex = Nothing
Set wb = Nothing
Set ws = Nothing
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
1
0
Would love your thoughts, please comment.x
()
x