codice:
Public Sub Report_Polizze_Attive(Path_File_Excel As String)
Dim db As Database
Dim rs As Recordset
Dim sql As String
Dim r, c As Integer
Dim ExcelApp As Object
Dim Worbk As Workbook
'**********************************************************************************
'CREAZIONE DEL FILE EXCEL
'**********************************************************************************
Open Path_File_Excel For Output As #1
Close #1
'**********************************************************************************
'CREAZIONE DELL'OGGETTO ExcelApp E APERTURA DEL FILE
'**********************************************************************************
Set ExcelApp = CreateObject("excel.application")
ExcelApp.Workbooks.Open Path_File_Excel
'**********************************************************************************
'CREAZIONE DELLA QUERY PER LE POLIZZE ATTIVE
'**********************************************************************************
sql = "select * from Tab"
'**********************************************************************************
'LETTURA DATI DAL DATABASE ED ESPORTAZIOINE IN EXCEL
'**********************************************************************************
Set db = DAO.OpenDatabase(Path_Db_access)
Set rs = db.OpenRecordset(sql)
r = 3
Do While Not rs.EOF
Cells(r, 1) = rs.Fields(0)
Cells(r, 2) = rs.Fields(1)
Cells(r, 3) = rs.Fields(2)
Cells(r, 4) = rs.Fields(3)
Cells(r, 5) = rs.Fields(4)
Cells(r, 6) = rs.Fields(5)
r = r + 1
rs.MoveNext
Loop
'**********************************************************************************
'RILASCIO DEGLIO OGGETTI E CHIUSURA DATABASE
'**********************************************************************************
db.Close
ExcelApp.Visible = True
Set ExcelApp = Nothing
End Sub
Non sò proprio perchè l'applicazione Excel rimane aperta...