Bonjour,
J'ai crée un programme en vba qui exporte les données d'un tableau (Userform) vers un fichier excel.
Le problème est que le programme va s'éffectuer normalement la première fois. La 2nd (sans modif) il y aurra un bug 1004.
CODE:
Sub Export_excel()
Dim i, j As Integer
Dim i0, j0 As Integer
'Evaluons le nombre de points
j0 = 0
i0 = 3
k = 0
While j0 < 1
If Tableau.Classeur1.Cells(i0, 1) <> "None" Then
k = k + 1
i0 = i0 + 1
Else
j0 = 1
End If
Wend
If k = 0 Then
MsgBox "Le tableau est vide"
Exit Sub
End If
Nbpoints = k + 1
Call AddNewWorkbook
'On créer l'objet Excel
'Set xlApp = CreateObject("Excel.Application")
'Set xlBook = xlApp.Worksbooks
'Ouvrir le fichier
'Workbooks.Open fileName:=lien_fichierxlsx
Workbooks(Nom_Fichier & ".xlsx").Activate Erreur '1004'
'Worksheets("Table Bouteille").Select
For i = 1 To Nbpoints + 1
Range("A" & i) = Tableau.Classeur1.Cells(i, 1)
Range("B" & i) = Tableau.Classeur1.Cells(i, 2)
Range("C" & i) = Tableau.Classeur1.Cells(i, 3)
Range("D" & i) = Tableau.Classeur1.Cells(i, 4)
Range("E" & i) = Tableau.Classeur1.Cells(i, 5)
Range("F" & i) = Tableau.Classeur1.Cells(i, 6)
Next
ActiveWorkbook.Save
ActiveWorkbook.Close
MsgBox "Exportation réussie!", vbMsgBoxSetForeground + vbExclamation, "TRAPRO DESIGN"
End Sub
Je vous joint la macro si vous voulez voir comment je l'ai fait.
Il faut créer un dossier: D:\Import-Export\ (ou changer le lien dans Userform_Initialize)
Merci beaucoup de vos réponses,
JB
copie_de_prog.swp