COME ESPORTARE I DATI DA ACCESS AD EXCEL

Click to rate this post!
[Total: 1 Average: 4]

Esempio molto semplice per esportare i dati da Access ad Excel creato un piccolo tools in VBA

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
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x