IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Word Discussion :

Erreur de compilation incompréhensible - membre de méthode ou de données introuvable


Sujet :

VBA Word

  1. #1
    Candidat au Club
    Homme Profil pro
    Juriste
    Inscrit en
    Septembre 2019
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Juriste

    Informations forums :
    Inscription : Septembre 2019
    Messages : 5
    Points : 4
    Points
    4
    Par défaut Erreur de compilation incompréhensible - membre de méthode ou de données introuvable
    Bonjour,

    J'ai un problème d'exécution de mon code qui a surgi de manière soudaine alors que le code fonctionnait normalement avant.

    Le message d'erreur est le suivant:

    Erreur de compilation
    Membre de méthode ou de données introuvables
    Le message d'erreur s'affiche en surlignant la ligne 165 de code suivante située en fin de code: xlWb.Close.

    Le code concerné est le code ci-dessous:

    Merci d'avance pour votre aide.

    TM

    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    Sub Prod_Facture()
    'Déclaration des variables
    Dim xlApp As Excel.Application
    Dim xlWb As Excel.Workbook
    Dim xlSh As Excel.Worksheet
    On Error GoTo err_handler
    Dim iR, jR, lR, mR As Integer
    Dim i, j, k, l, m As Integer
     
    Dim oDoc As Document
    Dim oTbl, oTb2, oTb3 As Table
    Dim stDocName As String
    Dim stPath As String
    Dim plage As Range, resultat As Integer
    Dim User As String
     
    User = "t.molierac"
     
    'Affectation des données aux variables
    Set xlApp = CreateObject("Excel.Application")
    Set xlWb = xlApp.Workbooks.Open("C:\Users\" & User & "\OneDrive - LEXIQUE\RESEAU LEXIQUE\FACTURE\PROD\SGBD_Facture_Production.xlsm")
    Set xlSh1 = xlWb.Worksheets(1)
    Set xlSh2 = xlWb.Worksheets(2)
    Set xlSh5 = xlWb.Worksheets(5)
    'Récupération du nombre de lignes et de colonnes
    iR = xlSh1.UsedRange.Rows.Count
    jR = xlSh2.UsedRange.Rows.Count
    err_handler:
       MsgBox "The code failed at line " & Erl, vbCritical
     
     For i = 41 To 41
            stDocName = "C:\Users\" & User & "\OneDrive - LEXIQUE\RESEAU LEXIQUE\FACTURE\DEF\" & Format(Now, "yyyy_mm_dd_") & xlSh1.Cells(i, 3) & "_" & xlSh1.Cells(i, 4) & "_" & xlSh1.Cells(i, 6) & ".docx"
            Set oDoc = Documents.Add("C:\Users\" & User & "\OneDrive - LEXIQUE\RESEAU LEXIQUE\FACTURE\PROD\Facture_Modèle_Production.docm")
            Set oTbl = oDoc.Tables(1)
            Set oTb2 = oDoc.Tables(2)
            Set oTb3 = oDoc.Tables(3)
     
            oDoc.Bookmarks("S1").Range.Text = xlSh1.Cells(i, 5)
            oDoc.Bookmarks("S2").Range.Text = xlSh1.Cells(i, 7)
            oDoc.Bookmarks("S3").Range.Text = xlSh1.Cells(i, 6)
            oDoc.Bookmarks("S4").Range.Text = xlSh1.Cells(i, 8)
            oDoc.Bookmarks("S5").Range.Text = xlSh1.Cells(i, 9)
            oDoc.Bookmarks("S6").Range.Text = xlSh1.Cells(i, 10)
            oDoc.Bookmarks("S7").Range.Text = xlSh1.Cells(i, 11)
            oDoc.Bookmarks("S8").Range.Text = xlSh1.Cells(i, 12)
            oDoc.Bookmarks("S9").Range.Text = xlSh1.Cells(i, 13)
            oDoc.Bookmarks("S10").Range.Text = xlSh1.Cells(i, 14)
            oDoc.Bookmarks("S0").Range.Text = xlSh1.Cells(i, 4)
            oDoc.Bookmarks("S21").Range.Text = Format(Now, "dd mmmm yyyy")
            oDoc.Bookmarks("SIBAN").Range.Text = xlSh5.Cells(3, 2)
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = xlSh1.Cells(i, 15)
            oTbl.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 18)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 19)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 20)
     
                For k = 2 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            oTbl.Rows.Last.Range.Font.Bold = False
     
            If xlSh1.Cells(i, 21) = 0 Then
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "TOTAL"
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 24)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 25)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 26)
                For k = 2 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            oTb3.Delete
     
            Else
     
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "Frais suivant détail ci-après"
            oTbl.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 21)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 22)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 23)
            oTbl.Rows.Last.Range.Font.Bold = False
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "TOTAL"
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 24)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 25)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 26)
                For k = 1 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            For j = 2 To jR
            If xlSh2.Cells(j, 3) = xlSh1.Cells(i, 4) Then
            oTb3.Rows.Add
            oTb3.Rows.Last.Cells(1).Range.Text = xlSh2.Cells(j, 12)
            oTb3.Rows.Last.Cells(2).Range.Text = xlSh2.Cells(j, 5) & " - " & xlSh2.Cells(j, 6)
            oTb3.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTb3.Rows.Last.Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTb3.Rows.Last.Cells(3).Range.Text = xlSh2.Cells(j, 9)
            oTb3.Rows.Last.Range.Font.Bold = False
            oTb3.Rows.Last.Cells(3).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            End If
     
            Next j
     
            End If
     
    Next i
     
    lR = oDoc.Tables(1).Rows.Count
     
    With oDoc.Tables(1)
        For l = 1 To lR
     
        .Rows(l).Height = CentimetersToPoints(1)
        .Rows(l).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next l
     
    End With
     
    If xlSh1.Cells(i, 21) <> 0 Then
     
    mR = oDoc.Tables(3).Rows.Count
     
    With oDoc.Tables(3)
        For m = 1 To mR
     
        .Rows(m).Height = CentimetersToPoints(1)
        .Rows(m).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next m
     
    End With
     
    End If
     
    oDoc.Tables(1).Rows.Last.Range.Font.Bold = True
     
    If xlSh1.Cells(i, 21) <> 0 Then
    oDoc.Tables(3).Rows.Last.Range.Font.Bold = True
    End If
     
    oTb2.Columns(1).Cells(2).Range.Text = xlSh1.Cells((i - 1), 24)
    oTb2.Columns(2).Cells(2).Range.Text = xlSh1.Cells((i - 1), 27)
    oTb2.Columns(3).Cells(2).Range.Text = xlSh1.Cells((i - 1), 25)
     
    With oDoc.Tables(2)
        For k = 1 To 2
     
        .Columns(k).Cells(k).Height = CentimetersToPoints(1)
        .Rows(k).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next k
     
        .Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
     
    End With
     
    oDoc.SaveAs stDocName
     
    oDoc.Close
     
    Set oDoc = Nothing
     
    xlWb.Close
    xlApp.Quit
    Set xlSh = Nothing
    Set xlWb = Nothing
    Set xlApp = Nothing
     
     
    End Sub
    Images attachées Images attachées

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    Mettez déjà un Option Explicit en tête de votre module, faites un débogage et créez les variables manquantes.

    Ces lignes sont bizarrement placées.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    err_handler:
    MsgBox "The code failed at line " & Erl, vbCritical
    Pour la fermeture de votre fichier Excel, complétez avec SaveChanges et l'option choisie.
    Dernière modification par Invité ; 03/09/2019 à 22h42. Motif: Ajout des balises [C] ... [/C]

  3. #3
    Candidat au Club
    Homme Profil pro
    Juriste
    Inscrit en
    Septembre 2019
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Juriste

    Informations forums :
    Inscription : Septembre 2019
    Messages : 5
    Points : 4
    Points
    4
    Par défaut erreur de compilation: membre de méthode ou de données introuvable
    Eric,

    Merci pour votre réponse rapide et claire.

    Le problème est résolu.

    Bien à vous,

    TM

  4. #4
    Candidat au Club
    Homme Profil pro
    Juriste
    Inscrit en
    Septembre 2019
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Juriste

    Informations forums :
    Inscription : Septembre 2019
    Messages : 5
    Points : 4
    Points
    4
    Par défaut Erreur de compilation, membre de méthode ou de données introuvable
    Bonjour,

    J'ai de nouveau le même problème alors que je n'ai pas modifié le code!!!

    Le message d'erreur suivant s'affiche à nouveau: erreur de compilation, membre de méthode ou de données introuvable.

    Avez-vous un conseil pour résoudre définitivement ce problème?

    Merci d'avance pour votre temps,

    Bien à vous,

    TM


    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
     
     
     
    Option Explicit
     
    Sub Prod_Facture()
     
    'Déclaration des variables
    Dim xlApp As Excel.Application
    Dim xlWb As Excel.Workbook
    Dim xlSh1, xlSh2, xlSh5 As Excel.Worksheet
    Dim iR, jR, lR, mR As Integer
    Dim i, j, k, l, m As Integer
     
    Dim oDoc As Document
    Dim oTbl, oTb2, oTb3 As Table
    Dim stDocName As String
    Dim stPath As String
    Dim plage As Range, resultat As Integer
    Dim User As String
     
    User = "t.molierac"
     
    'Affectation des données aux variables
    Set xlApp = CreateObject("Excel.Application")
    Set xlWb = xlApp.Workbooks.Open("C:\Users\" & User & "\OneDrive - LEXIQUE\RESEAU LEXIQUE\FACTURE\PROD\SGBD_Facture_Production.xlsx")
    Set xlSh1 = xlWb.Worksheets(1)
    Set xlSh2 = xlWb.Worksheets(2)
    Set xlSh5 = xlWb.Worksheets(5)
    'Récupération du nombre de lignes et de colonnes
    iR = xlSh1.UsedRange.Rows.Count
    jR = xlSh2.UsedRange.Rows.Count
     
     For i = 49 To 49
            stDocName = "C:\Users\" & User & "\OneDrive - LEXIQUE\RESEAU LEXIQUE\FACTURE\DEF\" & Format(Now, "yyyy_mm_dd_") & xlSh1.Cells(i, 3) & "_" & xlSh1.Cells(i, 4) & "_" & xlSh1.Cells(i, 6) & ".docx"
            Set oDoc = Documents.Add("C:\Users\" & User & "\OneDrive - LEXIQUE\RESEAU LEXIQUE\FACTURE\PROD\Facture_Modèle_Production.docm")
            Set oTbl = oDoc.Tables(1)
            Set oTb2 = oDoc.Tables(2)
            Set oTb3 = oDoc.Tables(3)
     
            oDoc.Bookmarks("S1").Range.Text = xlSh1.Cells(i, 5)
            oDoc.Bookmarks("S2").Range.Text = xlSh1.Cells(i, 7)
            oDoc.Bookmarks("S3").Range.Text = xlSh1.Cells(i, 6)
            oDoc.Bookmarks("S4").Range.Text = xlSh1.Cells(i, 8)
            oDoc.Bookmarks("S5").Range.Text = xlSh1.Cells(i, 9)
            oDoc.Bookmarks("S6").Range.Text = xlSh1.Cells(i, 10)
            oDoc.Bookmarks("S7").Range.Text = xlSh1.Cells(i, 11)
            oDoc.Bookmarks("S8").Range.Text = xlSh1.Cells(i, 12)
            oDoc.Bookmarks("S9").Range.Text = xlSh1.Cells(i, 13)
            oDoc.Bookmarks("S10").Range.Text = xlSh1.Cells(i, 14)
            oDoc.Bookmarks("S0").Range.Text = xlSh1.Cells(i, 4)
            oDoc.Bookmarks("S21").Range.Text = Format(Now, "dd mmmm yyyy")
            oDoc.Bookmarks("SIBAN").Range.Text = xlSh5.Cells(2, 2)
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = xlSh1.Cells(i, 15)
            oTbl.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 18)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 19)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 20)
     
                For k = 2 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            oTbl.Rows.Last.Range.Font.Bold = False
     
            If xlSh1.Cells(i, 21) = 0 Then
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "TOTAL"
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 24)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 25)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 26)
                For k = 2 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            oTb3.Delete
     
            Else
     
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "Frais suivant détail ci-après"
            oTbl.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 21)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 22)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 23)
            oTbl.Rows.Last.Range.Font.Bold = False
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "TOTAL"
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 24)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 25)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 26)
                For k = 1 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            For j = 2 To jR
            If xlSh2.Cells(j, 3) = xlSh1.Cells(i, 4) Then
            oTb3.Rows.Add
            oTb3.Rows.Last.Cells(1).Range.Text = xlSh2.Cells(j, 12)
            oTb3.Rows.Last.Cells(2).Range.Text = xlSh2.Cells(j, 5) & " - " & xlSh2.Cells(j, 6)
            oTb3.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTb3.Rows.Last.Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTb3.Rows.Last.Cells(3).Range.Text = xlSh2.Cells(j, 9)
            oTb3.Rows.Last.Range.Font.Bold = False
            oTb3.Rows.Last.Cells(3).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            End If
     
            Next j
     
            End If
     
     
     
    lR = oDoc.Tables(1).Rows.Count
     
    With oDoc.Tables(1)
        For l = 1 To lR
     
        .Rows(l).Height = CentimetersToPoints(1)
        .Rows(l).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next l
     
    End With
     
    If xlSh1.Cells(i, 21) <> 0 Then
     
    mR = oDoc.Tables(3).Rows.Count
     
    With oDoc.Tables(3)
        For m = 1 To mR
     
        .Rows(m).Height = CentimetersToPoints(1)
        .Rows(m).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next m
     
    End With
     
    End If
     
    oDoc.Tables(1).Rows.Last.Range.Font.Bold = True
     
    If xlSh1.Cells(i, 21) <> 0 Then
    oDoc.Tables(3).Rows.Last.Range.Font.Bold = True
    End If
     
    oTb2.Columns(1).Cells(2).Range.Text = xlSh1.Cells((i - 1), 24)
    oTb2.Columns(2).Cells(2).Range.Text = xlSh1.Cells((i - 1), 27)
    oTb2.Columns(3).Cells(2).Range.Text = xlSh1.Cells((i - 1), 25)
     
    With oDoc.Tables(2)
        For k = 1 To 2
     
        .Columns(k).Cells(k).Height = CentimetersToPoints(1)
        .Rows(k).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next k
     
        .Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
     
    End With
     
    oDoc.SaveAs stDocName
     
    Next i
     
    oDoc.Close
     
    Set oDoc = Nothing
     
    xlWb.Close
    xlApp.Quit
    Set xlSh1 = Nothing
    Set xlSh2 = Nothing
    Set xlSh5 = Nothing
    Set xlWb = Nothing
    Set xlApp = Nothing
     
     
    End Sub

  5. #5
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par VbTm_2019 Voir le message
    Bonjour,

    Je ne vois rien d'anormal. Il faudrait mettre en ligne un exemple de vos fichiers pour vérifier.

  6. #6
    Inactif  

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2012
    Messages
    4 903
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 68
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2012
    Messages : 4 903
    Points : 10 166
    Points
    10 166
    Billets dans le blog
    36
    Par défaut
    Bonjour,


    Citation Envoyé par VbTm_2019 Voir le message

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim xlSh1, xlSh2, xlSh5 As Excel.Worksheet
    Juste xlSh5 est défini comme Excel.Worksheet,
    Les deux autres sont des Variant.
    Pour avoir trois Excel.worksheet, il faut mettre as Excel.Worksheet à chaque fois

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Dim iR, jR, lR, mR As Integer
    Dim i, j, k, l, m As Integer
    Dim oTbl, oTb2, oTb3 As Table
    C'est exactement le même principe que pour As Excel.Worksheet.

    VBA permet les déclarations multiples sur la même ligne, mais chaque type doit être déclaré. Un type non déclaré est variant par défaut.

    Et c'est la même chose pour toutes les versions de VBA.

  7. #7
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par clementmarcotte Voir le message
    Bien vu Clément.

  8. #8
    Candidat au Club
    Homme Profil pro
    Juriste
    Inscrit en
    Septembre 2019
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Juriste

    Informations forums :
    Inscription : Septembre 2019
    Messages : 5
    Points : 4
    Points
    4
    Par défaut
    Bonjour,

    Merci à tous deux pour vos réponses.

    J'ai effectué les corrections proposées par Clément comme ci-dessous dans le code.
    Toutefois, le message d'erreur subsiste.

    Je vous joins le fichier excel et le fichier word utilisé par le code.

    J'ai supprimé les chemins d'accès en les remplaçant par xxx.

    D'avance merci pour votre revue,

    TM

    Facture_Modèle_Production_test.docxSGBD_Facture_Production_test.xlsx

    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
     
     
    Sub Prod_Facture()
     
    'Déclaration des variables
    Dim xlApp As Excel.Application
    Dim xlWb As Excel.Workbook
    Dim xlSh1 As Excel.Worksheet, xlSh2 As Excel.Worksheet, xlSh5 As Excel.Worksheet
    Dim iR As Integer, jR As Integer, lR As Integer, mR As Integer
    Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer
     
    Dim oDoc As Document
    Dim oTbl As Table, oTb2 As Table, oTb3 As Table
    Dim stDocName As String
    Dim stPath As String
    Dim plage As Range, resultat As Integer
    Dim User As String
     
     
    'Affectation des données aux variables
    Set xlApp = CreateObject("Excel.Application")
    Set xlWb = xlApp.Workbooks.Open("C:\Users\xxx\SGBD_Facture_Production_test.xlsx")
    Set xlSh1 = xlWb.Worksheets(1)
    Set xlSh2 = xlWb.Worksheets(2)
    Set xlSh5 = xlWb.Worksheets(5)
    'Récupération du nombre de lignes et de colonnes
    iR = xlSh1.UsedRange.Rows.Count
    jR = xlSh2.UsedRange.Rows.Count
     
     For i = 49 To 49
            stDocName = "C:\Users\xxx\DEF\" & Format(Now, "yyyy_mm_dd_") & xlSh1.Cells(i, 3) & "_" & xlSh1.Cells(i, 4) & "_" & xlSh1.Cells(i, 6) & ".docx"
            Set oDoc = Documents.Add("C:\Users\xxx\Facture_Modèle_Production_test.docm")
            Set oTbl = oDoc.Tables(1)
            Set oTb2 = oDoc.Tables(2)
            Set oTb3 = oDoc.Tables(3)
     
            oDoc.Bookmarks("S1").Range.Text = xlSh1.Cells(i, 5)
            oDoc.Bookmarks("S2").Range.Text = xlSh1.Cells(i, 7)
            oDoc.Bookmarks("S3").Range.Text = xlSh1.Cells(i, 6)
            oDoc.Bookmarks("S4").Range.Text = xlSh1.Cells(i, 8)
            oDoc.Bookmarks("S5").Range.Text = xlSh1.Cells(i, 9)
            oDoc.Bookmarks("S6").Range.Text = xlSh1.Cells(i, 10)
            oDoc.Bookmarks("S7").Range.Text = xlSh1.Cells(i, 11)
            oDoc.Bookmarks("S8").Range.Text = xlSh1.Cells(i, 12)
            oDoc.Bookmarks("S9").Range.Text = xlSh1.Cells(i, 13)
            oDoc.Bookmarks("S10").Range.Text = xlSh1.Cells(i, 14)
            oDoc.Bookmarks("S0").Range.Text = xlSh1.Cells(i, 4)
            oDoc.Bookmarks("S21").Range.Text = Format(Now, "dd mmmm yyyy")
            oDoc.Bookmarks("SIBAN").Range.Text = xlSh5.Cells(2, 2)
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = xlSh1.Cells(i, 15)
            oTbl.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 18)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 19)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 20)
     
                For k = 2 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            oTbl.Rows.Last.Range.Font.Bold = False
     
            If xlSh1.Cells(i, 21) = 0 Then
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "TOTAL"
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 24)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 25)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 26)
                For k = 2 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            oTb3.Delete
     
            Else
     
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "Frais suivant détail ci-après"
            oTbl.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 21)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 22)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 23)
            oTbl.Rows.Last.Range.Font.Bold = False
            oTbl.Rows.Add
            oTbl.Rows.Last.Cells(1).Range.Text = "TOTAL"
            oTbl.Rows.Last.Cells(2).Range.Text = xlSh1.Cells(i, 24)
            oTbl.Rows.Last.Cells(3).Range.Text = xlSh1.Cells(i, 25)
            oTbl.Rows.Last.Cells(4).Range.Text = xlSh1.Cells(i, 26)
                For k = 1 To 4
                oTbl.Rows.Last.Cells(k).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
                Next k
     
            For j = 2 To jR
            If xlSh2.Cells(j, 3) = xlSh1.Cells(i, 4) Then
            oTb3.Rows.Add
            oTb3.Rows.Last.Cells(1).Range.Text = xlSh2.Cells(j, 12)
            oTb3.Rows.Last.Cells(2).Range.Text = xlSh2.Cells(j, 5) & " - " & xlSh2.Cells(j, 6)
            oTb3.Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTb3.Rows.Last.Cells(2).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
            oTb3.Rows.Last.Cells(3).Range.Text = xlSh2.Cells(j, 9)
            oTb3.Rows.Last.Range.Font.Bold = False
            oTb3.Rows.Last.Cells(3).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            End If
     
            Next j
     
            End If
     
     
     
    lR = oDoc.Tables(1).Rows.Count
     
    With oDoc.Tables(1)
        For l = 1 To lR
     
        .Rows(l).Height = CentimetersToPoints(1)
        .Rows(l).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next l
     
    End With
     
    If xlSh1.Cells(i, 21) <> 0 Then
     
    mR = oDoc.Tables(3).Rows.Count
     
    With oDoc.Tables(3)
        For m = 1 To mR
     
        .Rows(m).Height = CentimetersToPoints(1)
        .Rows(m).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next m
     
    End With
     
    End If
     
    oDoc.Tables(1).Rows.Last.Range.Font.Bold = True
     
    If xlSh1.Cells(i, 21) <> 0 Then
    oDoc.Tables(3).Rows.Last.Range.Font.Bold = True
    End If
     
    oTb2.Columns(1).Cells(2).Range.Text = xlSh1.Cells((i - 1), 24)
    oTb2.Columns(2).Cells(2).Range.Text = xlSh1.Cells((i - 1), 27)
    oTb2.Columns(3).Cells(2).Range.Text = xlSh1.Cells((i - 1), 25)
     
    With oDoc.Tables(2)
        For k = 1 To 2
     
        .Columns(k).Cells(k).Height = CentimetersToPoints(1)
        .Rows(k).Cells.VerticalAlignment = wdAlignVerticalCenter
        Next k
     
        .Rows.Last.Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
     
    End With
     
    oDoc.SaveAs stDocName
     
    Next i
     
    oDoc.Close
     
    Set oDoc = Nothing
     
    xlWb.Close
    xlApp.Quit
    Set xlSh1 = Nothing
    Set xlSh2 = Nothing
    Set xlSh5 = Nothing
    Set xlWb = Nothing
    Set xlApp = Nothing
     
     
    End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2016] Erreur de compilation - - Membre de méthode ou de donnée introuvable
    Par Nospam54 dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 18/03/2019, 17h50
  2. [XL-2007] Erreur incompréhensible "Membre de méthode ou de données introuvable"
    Par ted the Ors dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 25/04/2017, 11h39
  3. [AC-2010] Erreur de compilation membre de méthode ou de données introuvable
    Par mcharmat dans le forum VBA Access
    Réponses: 3
    Dernier message: 12/05/2016, 00h32
  4. Réponses: 2
    Dernier message: 01/10/2010, 16h01
  5. Erreur de compilation: Membre de méthode ou de données introuvable
    Par toniodelavega dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 27/08/2010, 08h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo