Bonjour,
Le traitement est un peu compliqué et pas forcément satisfaisant pour les noms en majuscule car il faut exclure certains caractères et la liste que j'ai prise en compte n'est pas exhaustive. Afin d'écarter certains mots en majuscule, il faut travailler par tableau. A cet effet, j'ai ajouté un huitième tableau sans bordures correspondant à la partie signatures.
Le document contient deux macros lancées par les boutons rouge et vert dans la barre d'accès rapide.
La macro modifiant les noms :
Option Explicit
Sub MettreEnFormeLesNomsEnMajuscule()
Dim I As Integer, J As Integer, K As Integer
Dim WdDoc As Document
Application.ScreenUpdating = False
Set WdDoc = ActiveDocument
With WdDoc
For I = 1 To .Tables.Count
Select Case I
Case 1, 2, 8
With .Tables(I).Range
For J = 1 To .Cells.Count
With .Cells(J).Range
If .Words.Count > 0 Then
For K = 1 To .Words.Count
If MotMajuscule(.Words(K)) Then
Select Case .Words(K).Text
Case ":", "(", ")", "'", ",", "/", " ", Chr(13), " " & Chr(13), Chr(10), Chr(11), 0 To 9, "PORTALIS"
Case Else
If Len(.Words(K).Text) > 2 Then
'Debug.Print Trim(.Words(K))
.Words(K).Font.Bold = True
End If
End Select
End If
Next K
End If
End With
Next J
End With
End Select
Next I
End With
Set WdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function MotMajuscule(ByVal MotATraiter) As Boolean
MotMajuscule = False
If UCase(MotATraiter) = MotATraiter Then
MotMajuscule = True
End If
End Function
La macro modifiant les dates :
Option Explicit
Sub MettreEnFormeLesDates()
Dim I As Integer, IndexMatrice As Integer
Dim WdDoc As Document
Dim Matrice() As Variant
Dim MonRange As Range, RangeDepart As Range, RangeFin As Range
Application.ScreenUpdating = False
Set WdDoc = ActiveDocument
With WdDoc
IndexMatrice = 0
For I = 1 To .Words.Count
Select Case Trim(.Words(I).Text)
Case "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"
ReDim Preserve Matrice(IndexMatrice)
Matrice(IndexMatrice) = I
IndexMatrice = IndexMatrice + 1
End Select
Next I
For IndexMatrice = LBound(Matrice) To UBound(Matrice)
Selection.HomeKey unit:=wdStory
.Words(Matrice(IndexMatrice)).Select
Selection.MoveLeft unit:=wdCharacter, Count:=4
Set RangeDepart = Selection.Range
.Words(Matrice(IndexMatrice)).Select
Selection.MoveRight unit:=wdCharacter, Count:=8
Set RangeFin = Selection.Range
Set MonRange = WdDoc.Range(Start:=RangeDepart.Start, End:=RangeFin.End)
With MonRange.Font
.Bold = True
.Italic = True
.Underline = wdUnderlineWavyDouble
.Name = "Tahoma"
.Size = 12
.TextColor.RGB = RGB(0, 32, 96)
End With
Set MonRange = Nothing: Set RangeDepart = Nothing: Set RangeFin = Nothing
Next IndexMatrice
End With
Set WdDoc = Nothing
Application.ScreenUpdating = True
End Sub