Hello
I created a program in vba that exports data from a table (Userform) to an excel file.
The problem is that the program will run normally the first time. The 2nd (without modification) there will be a bug 1004.
CODE:
Sub Export_excel()
Sun i, j As Integer
Sun i0, j0 As Integer
Let's evaluate the number of points
j0 = 0
i0 = 3
k = 0
While j0 < 1
If Array.Workbook1.Cells(i0, 1) <> "None" Then
k = k + 1
i0 = i0 + 1
Else
d0 = 1
End If
Wend
If k = 0 Then
MsgBox "The table is empty"
Exit Sub
End If
Nbpoints = k + 1
Call AddNewWorkbook
'We create the Excel object
'Set xlApp = CreateObject("Excel.Application")
'Set xlBook = xlApp.Worksbooks
Open File
'Workbooks.Open fileName:=lien_fichierxlsx
Workbooks(Nom_Fichier & ".xlsx"). Activate Error '1004'
'Worksheets'. Select
For i = 1 TB Nbpoints + 1
Range("A" & i) = Array.Workbook1.Cells(i, 1)
Range("B" & i) = Array.Workbook1.Cells(i, 2)
Range("C" & i) = Array.Workbook1.Cells(i, 3)
Range("D" & i) = Array.Workbook1.Cells(i, 4)
Range("E" & i) = Array.Workbook1.Cells(i, 5)
Range("F" & i) = Array.Workbook1.Cells(i, 6)
Next
ActiveWorkbook.Save
ActiveWorkbook.Close
MsgBox "Export successful!", vbMsgBoxSetForeground + vbExclamation, "TRAPRO DESIGN"
End Sub
I'm attaching the macro to you if you want to see how I did it.
You need to create a folder: D:\Import-Export\ (or change the link in Userform_Initialize)
Thank you very much for your answers,
JB
copie_de_prog.swp