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
|
Public MatriceResultat() As Variant
Sub LaunchChoiceLanguageSentence()
Dim DocATraiter As Document
Dim X As Integer, PositionChaine As Integer
' Choisir la position de la phrase à sélectionner
PositionChaine = 2
Erase MatriceResultat
ChoiceLanguageSentence ActiveDocument, PositionChaine
End Sub
Sub ChoiceLanguageSentence(ByVal DocEnCours As Document, ByVal RangSelectionne As Integer)
Dim ParagrapheEnCours As Paragraph
Dim I As Integer, J As Integer, K As Integer, iNbEntreSlashs As Integer, iNbParagraphes As Integer, iMatrice As Integer
Dim EntrePointVirgules As Variant, EntreSlashs As Variant
Dim MatriceTextes() As Variant
Dim bSautTrouvé As Boolean
Dim Fin As Range
Dim MaSélection As Range
Dim ZoneRecherche As Range
Dim sSignet As String, sSelection As String
Dim MonDico As Collection
Set MonDico = New Collection
'Initialization
iMatrice = 0
'Rajouter les signets dans des dicos : ajout de la paire Clé + Valeur dans le Dictionnaire
MonDico.Add "1", "sec1_2_Relevant_identified_uses"
MonDico.Add "2", "sec1_2_Uses_advised_against"
iNbEntreSlashs = 0
iNbParagraphes = 0
For I = 1 To DocEnCours.Bookmarks.Count
sSignet = DocEnCours.Bookmarks.Item(I).Name
If CleEstPresente(MonDico, sSignet) = True Then 'Vérifier si le signet dans le dico
With DocEnCours
' zone de recherche du signet à la fin du document
Set ZoneRecherche = _
.Range(Start:=.Bookmarks(sSignet).Range.Start, _
End:=.Bookmarks("EndOfDoc").Range.End)
' recherche du saut de page manuel qui suit
ZoneRecherche.Find.ClearFormatting
With ZoneRecherche.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
End With
bSautTrouvé = ZoneRecherche.Find.Execute
If bSautTrouvé Then
Set Fin = ZoneRecherche
Else
' pas trouvé : fin = fin du document
Set Fin = .Bookmarks("EndOfDoc").Range
End If
' +1 pour inclure le saut de page dans la sélection
Set MaSélection = _
.Range(.Bookmarks(sSignet).Range.Start, _
Fin.End + 1)
MaSélection.Select
End With
' Next with the range select only what you need
sSelection = MaSélection.Text
If InStr(1, sSelection, ";", vbTextCompare) > 0 And InStr(1, sSelection, " / ", vbTextCompare) > 0 Then
EntrePointVirgules = Split(sSelection, ";")
For J = LBound(EntrePointVirgules) To UBound(EntrePointVirgules)
EntreSlashs = Split(EntrePointVirgules(J), " / ")
If iNbEntreSlashs < UBound(EntreSlashs) Then iNbEntreSlashs = UBound(EntreSlashs)
Next J
ReDim MatriceTextes(UBound(EntrePointVirgules), iNbEntreSlashs)
EntrePointVirgules = Split(sSelection, ";")
For J = LBound(EntrePointVirgules) To UBound(EntrePointVirgules)
EntreSlashs = Split(EntrePointVirgules(J), " / ")
For K = LBound(EntreSlashs) To UBound(EntreSlashs)
MatriceTextes(J, K) = EntreSlashs(K)
Next K
Next J
ReDim Preserve MatriceResultat(iNbParagraphes)
For J = LBound(MatriceTextes, 1) To UBound(MatriceTextes, 1)
MatriceResultat(iNbParagraphes) = MatriceResultat(iNbParagraphes) & MatriceTextes(J, RangSelectionne - 1) & ";"
Next J
MatriceResultat(iNbParagraphes) = Mid(MatriceResultat(iNbParagraphes), 1, Len(MatriceResultat(iNbParagraphes)) - 1)
iNbParagraphes = iNbParagraphes + 1
End If
' On a le texte à remplacer et la sélection dans un range suffit de faire le replace
MaSélection.Text = CStr(MatriceResultat(iMatrice)) + vbCrLf + vbCrLf
iMatrice = iMatrice + 1
End If
Next
'pour supprimer le Dictionnaire de la mémoire
Set MonDico = Nothing
End Sub
' Permet de savoir si une cle est présente dans le dico sans retourner d'erreur
Public Function CleEstPresente(Dico As Collection, Cle As Variant) As Boolean
Dim TestObject As Variant
On Error GoTo CleEstPresenteErreur
CleEstPresente = True
TestObject = Dico(Cle)
Exit Function
CleEstPresenteErreur:
CleEstPresente = False
End Function |
Partager