Bonjour,

J'essaye d'ouvrir un fichier Excel et a chaque fois cela bloque je ne comprend pas pourquoi.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Sub Explorer(p_strFichier As String, p_strCheminDepart As String, Optional p_oFld As Scripting.Folder)
 
    Dim j As Double
    Dim tableau_recap(80, 2) As Variant
    j = 0
 
 
    On Error GoTo err
 
        Dim oFSO As Scripting.FileSystemObject
        Dim oFld As Scripting.Folder
        Dim oFl As File
 
        If p_oFld Is Nothing Then
            'Instanciation du FSO
            Set oFSO = New Scripting.FileSystemObject
            'Accède au répertoire du départ de recherche
            Set p_oFld = oFSO.GetFolder(p_strCheminDepart)
        End If
        Set oFl = p_oFld.Files(p_strFichier)
 
        'MsgBox oFl.Path
 
'''''''''''''''*******************************
        'Traitement a faire quand le fichier est trouvé
 
    Dim wb As Workbook
    Dim ws As Worksheet
 
    Dim i As Long
    Dim adresse As String
    Dim continue As Boolean
 
  '  MsgBox oFl.Path
 
    MsgBox oFl.Path
 
 
    Set wb = Workbooks.Open(oFl.Path) ' Path contient ceci par exemple : "\\serveur2\Exploitation\Dossier SI\APP - Appli C2E\TODO_ List.xls"
    Set wb = Workbooks
    Set ws = wb.Worksheets(1)
 
 
    i = 0
    continue = 1
    While (continue)
        If ws.Cells(i, 1) <> Empty Then
            tableau_recap(j, 0) = ws.Cells(i, 1)
            tableau_recap(j, 1) = ws.Cells(i, 2)
            tableau_recap(j, 2) = ws.Cells(i, 3)
 
 
            MsgBox tableau_recap(j, 0)
            MsgBox tableau_recap(j, 1)
            MsgBox tableau_recap(j, 2)
 
            j = j + 1
        Else
            'quitte la boucle
            continue = 0
        End If
        i = i + 1
    Wend
 
 
    wb.Close Savechanges:=False ' fermeture du fichier
 
    'ActiveWindow.Close Savechanges:=False ' ne pas sauver les changements
    'Workbooks(nomfichier).Close Savechanges:=False
 
 
 
'''''''''''''''*******************************
 
 
 
SubDir:
    'Explore les sous-dossiers
        For Each oFld In p_oFld.SubFolders
            Explorer p_strFichier, p_strCheminDepart, oFld
            DoEvents
        Next oFld
 
fin:
        Exit Sub
 
err:
        Select Case err.Number
            Case 53: Resume SubDir
            Case Else:
                MsgBox "Erreur inconnue"
                Resume fin
        End Select
 
End Sub
A chaque fois que je fais une ouverture il me soulève une erreur, je ne sais si je m'y prend bien pour ouvrir le fichier