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
|
Sub MettreEnFormeLesNomsDePays()
Dim DocEnCours As Document
Dim I As Integer, J As Integer, K As Integer, NbCaracteres As Integer, IndexMatrice As Integer
Dim TableauDeValeurs As Variant, TableauPays() As Variant
Dim MotFormate As String
Dim MonRange As Range
IndexMatrice = 0
Set DocEnCours = ActiveDocument
With DocEnCours
For I = 1 To .Paragraphs.Count
With .Paragraphs(I).Range
' Debug.Print I & " : " & .Text
If InStr(1, .Text, "$", vbTextCompare) > 0 Then
TableauDeValeurs = Split(.Text, "$")
For J = LBound(TableauDeValeurs) To UBound(TableauDeValeurs)
NbCaracteres = 0
For K = 1 To Len(TableauDeValeurs(J))
Select Case Mid(TableauDeValeurs(J), K, 1)
Case "-", " "
NbCaracteres = NbCaracteres + 1
End Select
Next K
If NbCaracteres <= 1 And TableauDeValeurs(J) <> "" And TableauDeValeurs(J) <> Chr(13) Then
.Select
' Debug.Print Selection.Text
ReDim Preserve TableauPays(IndexMatrice)
'MajChaine Selection, TableauDeValeurs(J)
TableauPays(IndexMatrice) = TableauDeValeurs(J)
IndexMatrice = IndexMatrice + 1
' Debug.Print TableauDeValeurs(J)
End If
Next J
End If
End With
Next I
Selection.HomeKey unit:=wdStory
Set MonRange = .Content
For IndexMatrice = LBound(TableauPays) To UBound(TableauPays)
MotFormate = UCase(Mid(TableauPays(IndexMatrice), 1, 1)) & LCase(Mid(TableauPays(IndexMatrice), 2))
Debug.Print MotFormate
MonRange.Find.Execute FindText:=TableauPays(IndexMatrice), MatchCase:=True, ReplaceWith:=MotFormate, Replace:=wdReplaceAll
Next IndexMatrice
End With
Set MonRange = Nothing
Set DocEnCours = Nothing
End Sub |
Partager