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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
Option Explicit
Public MatriceSigles() As Variant, MatriceP() As Variant, MatricePos() As Variant
Public DicoPos As Object
Sub Sigle3()
Dim Sigle As String, Liste As String
Dim MaListe As Variant
Dim I As Integer, IndexMatrice As Integer, IndexP As Integer, IndexPos As Integer
Application.ScreenUpdating = False
Selection.HomeKey unit:=wdStory
'Recherche de toutes les expressions sous la forme "AGP [! ]@"
Do
Selection.Find.ClearFormatting
With Selection.Find
.ClearFormatting
.Text = "<AGP [! ]@>"
.Forward = True
.Wrap = wdFindStop
.MatchCase = True
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found Then
Sigle = Selection.Text
If InStr(Liste, Sigle) = 0 Then
Liste = Liste & Sigle & vbCr
End If
End If
Loop Until Not Selection.Find.Found
'Recherche de toutes les expressions sous la forme "<A[0-9]{5}>"
Selection.HomeKey unit:=wdStory
Do
Selection.Find.ClearFormatting
With Selection.Find
.ClearFormatting
.Text = "<A[0-9]{5}>"
.Forward = True
.Wrap = wdFindStop
.MatchCase = True
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found Then
Sigle = Selection.Text
If InStr(Liste, Sigle) = 0 Then
Liste = Liste & Sigle & vbCr
End If
End If
Loop Until Not Selection.Find.Found
MaListe = Split(Liste, Chr(13))
IndexMatrice = 0
For I = LBound(MaListe) To UBound(MaListe)
ReDim Preserve MatriceSigles(2, IndexMatrice)
If MaListe(I) <> "" Then
MatriceSigles(0, IndexMatrice) = MaListe(I)
IndexMatrice = IndexMatrice + 1
End If
Next I
RecherchePositionChaine
Liste = ""
For IndexP = LBound(MatriceP, 2) To UBound(MatriceP, 2)
For IndexPos = LBound(MatricePos, 2) To UBound(MatricePos, 2)
For IndexMatrice = LBound(MatriceSigles, 2) To UBound(MatriceSigles, 2)
If MatriceSigles(1, IndexMatrice) = MatriceP(0, IndexP) And MatriceSigles(2, IndexMatrice) = MatricePos(0, IndexPos) Then
If MatriceSigles(0, IndexMatrice) <> "" Then Liste = Liste & MatriceSigles(0, IndexMatrice) & vbCr
End If
Next IndexMatrice
Next IndexPos
Next IndexP
'Aller au tableau Reference Interne
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=1, Name:=""
'Insérer les expressions
Selection.TypeText Text:=Liste
PresentationDeLaListe
'Debug.Print Liste
End Sub
Sub RecherchePositionChaine()
Dim I As Integer, J As Integer, PositionTexte As Integer, IndexP As Integer, IndexPos As Integer, NbPos As Integer
Dim Tempo1 As Variant
Set DicoPos = CreateObject("Scripting.Dictionary")
With ActiveDocument
IndexP = 0
IndexPos = 0
NbPos = 0
For J = 1 To .Paragraphs.Count
.Paragraphs(J).Range.Select
' Continuer = True
For I = LBound(MatriceSigles, 2) To UBound(MatriceSigles, 2)
PositionTexte = InStr(1, Selection.Range, MatriceSigles(0, I), vbTextCompare)
If Not DicoPos.Exists(CStr(PositionTexte)) Then
DicoPos.Add CStr(PositionTexte), CStr(PositionTexte)
ReDim Preserve MatricePos(1, IndexPos)
MatricePos(0, IndexPos) = PositionTexte
IndexPos = IndexPos + 1
End If
If PositionTexte > 0 And MatriceSigles(1, I) = "" Then
MatriceSigles(1, I) = J
MatriceSigles(2, I) = PositionTexte
If J > IndexP Then
ReDim Preserve MatriceP(1, IndexP)
MatriceP(0, IndexP) = J
IndexP = IndexP + 1
End If
End If
Next I
Next J
' Tri des positions par ordre croissant
'--------------------------------------
For I = LBound(MatricePos, 2) To UBound(MatricePos, 2)
For J = I To UBound(MatricePos, 2)
If MatricePos(0, I) > MatricePos(0, J) Then
Tempo1 = MatricePos(0, J)
MatricePos(0, J) = MatricePos(0, I)
MatricePos(0, I) = Tempo1
End If
Next J
Next I
End With
Set DicoPos = Nothing
End Sub
Sub PresentationDeLaListe()
Selection.SelectCell
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = CentimetersToPoints(0.1)
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints(0.5)
.TabPosition = wdUndefined
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Bold = wdUndefined
.Italic = wdUndefined
.StrikeThrough = wdUndefined
.Subscript = wdUndefined
.Superscript = wdUndefined
.Shadow = wdUndefined
.Outline = wdUndefined
.Emboss = wdUndefined
.Engrave = wdUndefined
.AllCaps = wdUndefined
.Hidden = wdUndefined
.Underline = wdUndefined
.Color = wdUndefined
.Size = wdUndefined
.Animation = wdUndefined
.DoubleStrikeThrough = wdUndefined
.Name = "Symbol"
End With
.LinkedStyle = ""
End With
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _
ListGalleries(wdBulletGallery).ListTemplates(1), ContinuePreviousList:= _
False, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _
wdWord10ListBehavior
End Sub |
Partager