Erreur occationnel lors de l'exécution de mon code

Bonjour , je poste mon code en espérant trouver une solution à mon code qui peut buguer pendant l’exécution et toujours au même endroit.

en le faisant fonctionner pas à pas il bug jamais mais en le lançant ça arrive 1 fois sur 2.

Merci de votre réponse.

je vous donne mon code plus un fichier contenant les données à exploiter (rien de sensible c'est du gcode).

Sub listeLynx()
lynx-0417.txt
With Application.FileDialog(msoFileDialogFolderPicker)
    .Show
    If .SelectedItems.Count > 0 Then
    chemin = .SelectedItems(1) + "\"
    nom_dossier = Right(.SelectedItems(1), Len(.SelectedItems(1)) - Len(Left(.SelectedItems(1), InStrRev(.SelectedItems(1), "\"))))
    End If
End With
     Sheets.Add(After:=ActiveSheet).Name = nom_dossier
NomFichier = Dir(chemin)
MonFichier = chemin & NomFichier
prog = 1
While NomFichier <> ""
    Range(Cells(1, prog), Cells(1, prog + 1)).Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
    ActiveCell.FormulaR1C1 = NomFichier
    Cells(2, prog).Select
    ActiveCell.FormulaR1C1 = "Num_Outil"
    Cells(2, prog + 1).Select
    ActiveCell.FormulaR1C1 = "Outil"
    Ligne = 3
    MonFichier = chemin & NomFichier
    IndexFichier = FreeFile()
    Open MonFichier For Input As #IndexFichier 'ouvre le fichier

    While Not EOF(IndexFichier)
        Line Input #IndexFichier, ContenuLigne
        '-----identification si Unix ou Ctrlf ----------
        If Len(ContenuLigne) > 150 Then 'si oui >> Unix
            Fichier = Split(ContenuLigne, Chr(10))
            Ligne_en_cours = 1
            boucle_fichier = 0
            While boucle_fichier = 0
            If Fichier(Ligne_en_cours) = "%" Then
                boucle_fichier = 1
            Else

                If (Left(Fichier(Ligne_en_cours), 1) = "N" Or Left(Fichier(Ligne_en_cours), 1) = "T") And Len(Fichier(Ligne_en_cours)) > 15 And InStr(1, Fichier(Ligne_en_cours), "T") > 0 Then
                '--------------cas NxTxxxMxx(outil) ou cas TxxxMxx(outil)-----------

                '-------------Partie qui bug pendant l'execution--------
                    Ligne_Fichier = Split(Fichier(Ligne_en_cours), "(")

                            Partie_Ligne = Split(Ligne_Fichier(1), " ")
                '----------------------------------------------------------

                            position_table = 0
                            TypeDiam = ""
                            boucle_ligne = 0

                            tableau_outil = Split(Ligne_Fichier(0), "T")
                            test_num_outil = UBound(tableau_outil) + 1
                            If test_num_outil = 1 Then
                                If Len(tableau_outil(0)) <= 3 Or tableau_outil(0) = "N100" Then
                                 boucle_ligne = 1
                                Else
                                    num_outil = "T" + Left(tableau_outil(0), 2)
                                End If
                            Else
                                If Len(tableau_outil(1)) <= 3 Or tableau_outil(1) = "N100" Then
                                 boucle_ligne = 1
                                Else
                                num_outil = "T" + Left(tableau_outil(1), 2)
                                End If
                            End If
                            While boucle_ligne = 0 ' boucle de découpe de l'outil
                            If Right(Partie_Ligne(position_table), 1) = ")" Then ' sortie boucle
                                boucle_ligne = 1
                                Partie_Ligne(position_table) = Left(Partie_Ligne(position_table), Len(Partie_Ligne(position_table)) - 1)
                                TypeDiam = TypeDiam + " " + Partie_Ligne(position_table)
                            Else
                            TypeDiam = TypeDiam + " " + Partie_Ligne(position_table)
                            position_table = position_table + 1
                            End If
                            Wend

                            If TypeDiam <> "" Then
                            Cells(Ligne, prog + 1) = TypeDiam
                            Cells(Ligne, prog) = num_outil
                            Ligne = Ligne + 1
                            End If
                    End If
            Ligne_en_cours = Ligne_en_cours + 1
            End If
        Wend
    End If
    Wend
    Close #IndexFichier ' ferme le fichier
    Application.ScreenUpdating = True
    Range(Cells(3, prog), Cells(Ligne, prog)).Select
    ActiveSheet.UsedRange.RemoveDuplicates Columns:=1, Header:=xlYes
prog = prog + 2
NomFichier = Dir
Wend
End Sub

bonjour,

tu as très probablement une erreur lorsque ta macro execute ces instructions mais que ta ligne en cours ne contient pas le caractère "(". dans ce cas, ligne_fichier(1) n'existe pas.

              '-------------Partie qui bug pendant l'execution--------
                    Ligne_Fichier = Split(Fichier(Ligne_en_cours), "(")

                            Partie_Ligne = Split(Ligne_Fichier(1), " ")
                '----------------------------------------------------------

Sinon merci d'être plus précis, indiquer laquelle des 2 lignes donne une erreur et avec quel code d'erreur

bonjour,

peux-tu également mettre un fichier lynx.txt qui provoque une erreur ?

Rechercher des sujets similaires à "erreur occationnel lors execution mon code"