Erreur 1004 : Application-defined or object-defined error
Bonjour,
J'ai écrit une fonction ChargeDatas (ci-dessous) qui doit charger différents type de fichiers "à plat" dans différents fichier/onglets/cellules. Et qui me retourne le n° de la dernière ligne lue car je m'en sert plus tard pour la mise en forme.
Lors de l'éxécution de cette fonction, je n'ai aucun pb sur un petit fichier (moins de 65536 lignes), mais sur un gros fichier (115000 lignes), j'ai l'erreur "1004 : Application-defined or object-defined error" dans ma fonction. Et bien sûr le pb survient lors du traitement de la 65536ème ligne.... comme par hasard.
J'ai pourtant tout défini en Long, mais ça ne veut pas passer. Et à force de chercher j'ai les yeux qui se croisent...
Si quelqu'un veut bien m'aider.
Merci d'avance.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| Function ChargeDatas(Repert as String, NomFic as String, NomOngl as String, LigDebData as Long, ColMax as Long) As Long
Dim LILIG As Long
Dim LICOL As Long
On Error GoTo Err_Execute
ChargeDatas = -1
Application.CutCopyMode = False
Workbooks.OpenText Filename:=Repert & NomFic, _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= xlNone, ConsecutiveDelimiter:=False, _
Tab:=False, Semicolon:=True, Comma:=False, Space:=False, Other:=False, DecimalSeparator:=",", TrailingMinusNumbers:=True
LILIG = 0
If ColMax = 0 Then ColMax = 255
Do While Not IsEmpty(Cells(LILIG + 1, 1))
For LICOL = 1 To ColMax
Workbooks(NomXls).Sheets(NomOngl).Cells(LILIG + LigDebData, LICOL) = Cells(LILIG + 1, LICOL)
Next
LILIG = LILIG + 1
Loop
Workbooks(NomFic).Close SaveChanges:=False
ChargeDatas = LILIG
Exit Function
Err_Execute:
Call ModuleCommun.WriLog("A", "===> Erreur Chargement données : " & Err.Number & " : " & Err.Description)
End Function |