Salut Mortalino et MPI,
Premièrement, merci d'avoir répondu, ensuite.
Pour répondre à MPI, je travail en VB.
Pour Mortalino, j'ai un petit souci avec ton code. Tout d'abord, je l'ai mis dans un module, ensuite je l'ai inclus dans mon code de cette façon :
Private Sub Cmdexcel_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Dim b, l As Integer
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add
Set XlSheet = xlBook.Worksheets(1)
'' désactive les messages d'Excel
xlApp.Application.DisplayAlerts = False
If OpenDocXlsFile(App.Path & "\relevé.xls") = 0 Then
msg = MsgBox("Veuillez fermer le fichier relevé.xls" & Chr(10) & "pour pouvoir récupérer les données", vbCritical)
GoTo fin
End If
' Ouvre le fichier
xlApp.Workbooks.Open FileName:=App.Path & "\relevé.xls", Editable:=True, ReadOnly:=False
b = Lstview1.ListItems.Count
For a = 1 To b
l = xlApp.Sheets("donnees").Range("A65536").End(xlUp).row + 1
Set ObjListe = Nothing
Set ObjListe = Lstview1.ListItems(a)
xlApp.Sheets("donnees").Range("A" & l).Value = Lstview1.ListItems.Item(1)
xlApp.Sheets("donnees").Range("B" & l).Value = ObjListe.SubItems(1)
xlApp.Sheets("donnees").Range("C" & l).Value = ObjListe.SubItems(2)
xlApp.Sheets("donnees").Range("D" & l).Value = ObjListe.SubItems(3)
xlApp.Sheets("donnees").Range("E" & l).Value = ObjListe.SubItems(4)
xlApp.Sheets("donnees").Range("F" & l).Value = ObjListe.SubItems(5)
xlApp.Sheets("donnees").Range("G" & l).Value = ObjListe.SubItems(6)
xlApp.Sheets("donnees").Range("H" & l).Value = ObjListe.SubItems(7)
xlApp.Sheets("donnees").Range("I" & l).Value = ObjListe.SubItems(8)
xlApp.Sheets("donnees").Range("J" & l).Value = ObjListe.SubItems(9)
xlApp.Sheets("donnees").Range("K" & l).Value = ObjListe.SubItems(10)
xlApp.Sheets("donnees").Range("L" & l).Value = ObjListe.SubItems(11)
xlApp.Sheets("donnees").Range("M" & l).Value = ObjListe.SubItems(12)
Next a
fin:
xlApp.ActiveWorkbook.Save
xlApp.Application.DisplayAlerts = True
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set XlSheet = Nothing
End Sub
Le problème, et qu'il m'ouvre à chaque fois un fichier excel et que dans tous les cas, je n'arrive pas à enregistrer les données.
Je pense que je n'utilise pas ton code correctement. Peux-tu me mettre sur le bon rail. Merci
Joyeuses Pâques à vous
@+++
marcod59