Enregistrer dans un fichier excel

netfric Messages postés 17 Date d'inscription vendredi 26 octobre 2007 Statut Membre Dernière intervention 22 novembre 2007 - 2 nov. 2007 à 19:47
netfric Messages postés 17 Date d'inscription vendredi 26 octobre 2007 Statut Membre Dernière intervention 22 novembre 2007 - 3 nov. 2007 à 16:34
salut
j'ai ce code pour inserer dans un nouveux claseur mais pour un classeur exsistant je ne sais pas comment
merci de bien vouloir m'aider

  Dim Appli As New Application
  Dim Ligne As String
  Dim LigneExcel As Integer
  Dim compt As Integer


Appli.Visible = True
Appli.Workbooks.Add.Activate
LigneExcel = 1


For compt = 0 To List1.ListCount - 1
  With ActiveWorkbook.Worksheets("Feuil1")
    .Cells(LigneExcel, 1) = LigneExcel
    .Cells(LigneExcel, 2) = List1.List(compt)
    LigneExcel = LigneExcel + 1
  End With
Next compt

2 réponses

Molenn Messages postés 797 Date d'inscription mardi 7 juin 2005 Statut Membre Dernière intervention 23 février 2011 7
3 nov. 2007 à 00:56
Une solution serait d'ouvrir dans un premier temps ton classeur existant, sans doute avec un code du style :
Appli.Workbooks.open(C:\toto.xls)

Ensuite, dans ton code, remplacer ActiveWorkbook par Workbooks("toto.xls"), un truc de ce genre :
For compt = 0 To List1.ListCount - 1
  With Workbooks("toto.xls").Worksheets("Feuil1")
    .Cells(LigneExcel, 1) = LigneExcel
    .Cells(LigneExcel, 2) = List1.List(compt)
    LigneExcel = LigneExcel + 1
  End With
Next compt

Molenn
0
netfric Messages postés 17 Date d'inscription vendredi 26 octobre 2007 Statut Membre Dernière intervention 22 novembre 2007
3 nov. 2007 à 16:34
inpossible d'ouvrir le fichier

  Dim Appli As New Application
  Dim Ligne As String
  Dim LigneExcel As Integer
  Dim compt As Integer
 
Appli.Visible = True
Appli.Workbooks.Open ("C:\a3_3\creer\a3.xls")


LigneExcel = 1


For compt = 0 To List1.ListCount - 1
  With Workbooks("C:\a3_3\creer\a3.xls").Worksheets("Feuil1")
    .Cells(LigneExcel, 1) = LigneExcel
    .Cells(LigneExcel, 2) = List1.List(compt)
    LigneExcel = LigneExcel + 1
  End With
Next compt
0
Rejoignez-nous