Modifier un tableau présent dans un tableau
Bonjour le Forum,
J'ai fait une macro permettant de modifier n'importe quel tableaux s'il contient le titre "VOITURE" (Propriétés du tableau --> Texte de remplacement --> Titre).
Voici le code :
Private Sub Modifier_voitures_Click()
Dim tab_1 As Table
Dim I As Integer, J As Integer
Dim Reference As Variant
On Error GoTo Fin
With ActiveDocument
If .Tables.Count >= 1 Then
For Each tab_1 In ActiveDocument.Tables
If tab_1.Title = "VOITURE" Then
Do While tab_1.Columns.Count <= 1
With tab_1
If .Rows.Count = 1 Then GoTo Fin
.Columns(1).Select
Selection.InsertColumnsRight
Selection.InsertColumnsRight
Selection.InsertColumnsRight
.Columns.Width = InchesToPoints(1.1)
' Ligne 1
.Cell(Row:=1, Column:=2).Range.Text = "Modèle"
.Cell(Row:=1, Column:=2).Range.Bold = True
.Cell(Row:=1, Column:=2).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Cell(Row:=1, Column:=3).Range.Text = "Prix"
.Cell(Row:=1, Column:=3).Range.Bold = True
.Cell(Row:=1, Column:=3).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Cell(Row:=1, Column:=4).Range.Text = "Date d'achat"
.Cell(Row:=1, Column:=4).Range.Bold = True
.Cell(Row:=1, Column:=4).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
' Lignes suivantes
For I = 2 To .Rows.Count
With .Cell(Row:=I, Column:=1).Range
Reference = Mid(.Text, 1, Len(.Text) - 2)
End With
Next I
End With
Loop
End If
Next tab_1
End If
End With
GoTo Fin
Fin:
Set tab_1 = Nothing
End Sub
La macro fonctionne bien, elle modifie les tableaux en leur ajoutant des colonnes et en donnant des noms aux colonnes.
Le problème est que quand je positionne ce tableau dans un même tableau. Plus rien ne fonctionne, comme si le code arrivait pas à détecter le tableau, comme s'il ne faisait plus qu'un avec l'autre tableau. Je sais pas si vous m'avez compris.
Si quelqu'un a une solution pour parvenir à modifier ces tableaux même s'ils sont présents sur un autre tableau, je lui serai vraiment reconnaissants.
J'ai mis en PJ, le fichier word de test qui contient les macros et des exemples de tableaux pour que vous visualisez le problème.
Très bonne journée à vous !