Bonjour le Forum,

J'ai un problème avec Excel qui bug après l’exécution de la macro ci dessous :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim chemin1, chemin2, fichier, nom, NomRep, NumOE 
 
Sheets("Front").Activate
 
NumOE = "OE" & Range("E2") & Range("H2") & Range("K2")
nom = "OE" & Range("E2") & Range("H2") & Range("K2") & ".xls"
Application.DisplayAlerts = True
Application.EnableEvents = False
If a = 1 Then
    a = 0
ElseIf ThisWorkbook.Name = "OE excel.xls" And Range("R56").Value <> "" Then
    chemin1 = "F:\etude_daco\renault\0 - Suivi\Suivi des OE"
    NomRep = NumOE & " - " & InputBox("Rentrez le titre du dossier à créer.", "Création dossier")
 
    If NomRep <> NumOE & " - " Then
        NomRep = NomRep
    Else
        Application.EnableEvents = True
        Application.DisplayAlerts = True
        Exit Sub
    End If
 
    chemin2 = chemin1 & "\" & NomRep
    fichier = chemin2 & "\" & nom
 
    If Dir(chemin1 & "\" & NomRep, vbDirectory + vbHidden) = "" Then
        MkDir chemin1 & "\" & NomRep
    End If
 
    Filename = Application.GetSaveAsFilename(fichier, "Fichier excel (*.xls),*.xls")
 
    If Filename <> False Then
        ThisWorkbook.SaveAs Filename
    End If
 
    a = 1
End If
Application.EnableEvents = True
Application.DisplayAlerts = False
 
End Sub
Tout se déroule bien jusqu'à la ligne 34.

Dès que le fichier s'enregistre, excel bug et redémarre tout seul.

Mon fichier est bien enregistré au bon endroit, mais y a t il un moyen qu'excel ne plante pas quand le fichier bug?

Merci d'avance à ceux qui pourront m'aider.

Gaëtan