user_mobilelogo

Peut-on faire en forme conditionnelle dans un tableau, comme pour Excel ?

La réponse est non. La mise en forme automatique en fonction du texte saisi dans un tableau n'existe pas dans Word, et n'espérez pas non plus une macro événementielle.

Par contre, on peut créer une macro qu'on lancera une fois la saisie faite.

Voici par exemple une macro qui va colorer en jaune les cellules de la deuxième colonne, du premier tableau, si celles-ci contiennent une croix (X) :

Sub colore_tablo()
'macro écrite par m@rina
Dim cellule As Cell, tablo As Table

Set tablo = ActiveDocument.Tables(1)
    For Each cellule In tablo.Columns(2).Cells
        If Left(cellule.Range.Text, 1= "X" Then
            cellule.Shading.BackgroundPatternColor = wdColorYellow
            Else: cellule.Shading.BackgroundPatternColor = wdColorAutomatic
        End If
    Next
End Sub

 

Pour appliquer ce code à tous les tableaux du document, on fera une boucle :

Sub colore_tablo2()
'macro écrite par m@rina
Dim cellule As Cell, tablo As Table
For Each tablo In ActiveDocument.Tables
    For Each cellule In tablo.Columns(2).Cells
        If Left(cellule.Range.Text, 1= "X" Then
            cellule.Shading.BackgroundPatternColor = wdColorYellow
            Else: cellule.Shading.BackgroundPatternColor = wdColorAutomatic
        End If
    Next
Next tablo
End Sub
 

 

 

Statistiques

Aujourd'hui1381
Hier1893
Cette semaine8450
Ce mois27743
Total depuis 200418230283

15
visiteurs actuellement en ligne

19 avril 2024