Bonjour, lorsque j'exécute le code ci-dessous, la première fois tout fonctionne correctement, mais lorsque je relance cette fonction une deuxième de suite alors il me pose un problème
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
Private Sub Command2_Click()
    Dim MyWord As Word.Application
    Dim doc As Word.Document
    Set MyWord = New Word.Application
    With MyWord
        .Documents.Open(CHEMIN2)
        Selection.WholeStory
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
        Selection.Font.Size = 20
        Selection.Font.Bold = wdToggle
        Selection.TypeText Label1 ' écrit le titre
        Selection.TypeParagraph ' a la ligne
        Selection.TypeParagraph
        '''''''''''''''''''''''''''''''''''
        ' récupérer le nombre de colonnes '
        '''''''''''''''''''''''''''''''''''
        Dim VARC, VARL As Integer
        VARC = Form5.MSFlexGrid1.Cols
        VARL = Form5.MSFlexGrid1.Rows
 
        Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
        ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=VARL, NumColumns:=VARC, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitContent
        With Selection.Tables(1)
            If .Style <> "Grille du tableau" Then
                .Style = "Grille du tableau"
            End If
            .ApplyStyleHeadingRows = True
            .ApplyStyleLastRow = True
            .ApplyStyleFirstColumn = True
            .ApplyStyleLastColumn = True
        End With
        For i = 0 To VARL - 1
            For j = 0 To VARC - 1
                Selection.TypeText Text:=Form5.MSFlexGrid1.TextMatrix(i, j)
                Selection.MoveRight Unit:=wdCell
            Next j
        Next i
        'doc.SaveAs App.Path & "\stat.doc" ' enregistre sous un autre nom
        .Visible = True ' rend l'application visible
    End With
    Set MyWord = Nothing
    Set doc = Nothing
End Sub
Voici l'erreur
Erreur 462 : Le serveur distant n'existe pas ou est indisponible
Pourriez-vous m'aider ?