Ciao, sono riuscita a creare il codice che legge il file.xls ed importa in due tabelle access il contenuto, ora mi piacerebbe capire se è possibile fare quello di cui sopra per il quale non ho assolutamente idee...
Public Function import_excel()
Dim rs_t As ADODB.Recordset
Dim rs_r As ADODB.Recordset
Dim connessione As ADODB.Connection
Dim riga As Integer
Set connessione = CurrentProject.Connection
Set rs_t = New ADODB.Recordset
Set rs_r = New ADODB.Recordset
riga = 10
rs_t.Open "tmp_FORMULE_TESTA", connessione, adOpenKeyset, adLockOptimistic, adCmdTable
rs_r.Open "tmp_FORMULE_RIGA", connessione, adOpenKeyset, adLockOptimistic, adCmdTable
Dim xlApp As Object 'Excel.Application
Dim xlWrk As Object 'Excel.Workbook
Dim xlSheet As Object 'Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlWrk = xlApp.Workbooks.Open("C:\utn\FORMULA.xlsx")
Set xlSheet = xlWrk.Sheets("formula")
rs_t.AddNew
rs_t!CODART_SL = xlSheet.Cells(1, 1)
rs_t!DESCRIZIONE = Trim(xlSheet.Cells(5, 2)) + " " + Trim(xlSheet.Cells(6, 2)) + " " + Trim(xlSheet.Cells(7, 2))
rs_t!PS = xlSheet.Cells(1,
rs_t.Update
Dim fine As String
fine = Left(xlSheet.Cells(riga, 7), 3)
Do While fine <> "==="
' riga valida
r_valida = xlSheet.Cells(riga, 1)
' nota valida
n_valida = xlSheet.Cells(riga, 2)
If r_valida <> "" Then
rs_r.AddNew
rs_r!CODART_SL_MP = rs_t!CODART_SL
rs_r!codart_mp = xlSheet.Cells(riga, 1)
rs_r!DESCRIZIONE = xlSheet.Cells(riga, 2)
rs_r!UM = xlSheet.Cells(riga, 6)
rs_r!QUANTITA = xlSheet.Cells(riga, 7)
rs_r!COSTO = xlSheet.Cells(riga,
rs_r!TOTALE = xlSheet.Cells(riga, 9)
rs_r.Update
Else
If n_valida <> "" Then
rs_r!NOTE1 = xlSheet.Cells(riga, 2)
rs_r.Update
End If
End If
riga = riga + 1
fine = Left(xlSheet.Cells(riga, 7), 3)
Loop
rs_r.Close
rs_t.Close
Set rs_t = Nothing
Set rs_r = Nothing
Set xlSheet = Nothing
xlWrk.Close
Set xlWrk = Nothing
xlApp.Quit
Set xlApp = Nothing
End Function
grazie Paola
p.s. quale dei libri che consigliate in questo forum è meglio che utilizzi per capire al meglio VB x access