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
|
Sub OrganiserLesTraductions()
Dim DocSource As Document, DocCible As Document
Dim ParagrapheTitre As Paragraph
Dim MatriceDesTitres() As Variant, MatriceStyleNormal() As Variant, MatriceStyleQuechua() As Variant
Dim I As Integer, J As Integer
Dim NbParagraphesTitre As Integer, NbParagraphesNormaux As Integer, NbParagraphesQuechua As Integer
Dim MonRangeTitre As Range, MonRangeCible As Range
Dim StyleTitre As String, StyleNormal As String, StyleQuechua As String, Titre1EnCours As String
StyleTitre = "Titre 1"
StyleNormal = "Normal"
StyleQuechua = "Sous-titre" ' A adapter
Set DocSource = ActiveDocument
With DocSource
NbParagraphesTitre = 0
NbParagraphesNormaux = 0
NbParagraphesQuechua = 0
For I = 1 To .Paragraphs.Count
Select Case .Paragraphs(I).Style
Case StyleTitre
Titre1EnCours = .Paragraphs(I).Range.Text
ReDim Preserve MatriceDesTitres(1, NbParagraphesTitre)
MatriceDesTitres(0, NbParagraphesTitre) = Titre1EnCours
MatriceDesTitres(1, NbParagraphesTitre) = I
NbParagraphesTitre = NbParagraphesTitre + 1
Case StyleNormal
ReDim Preserve MatriceStyleNormal(1, NbParagraphesNormaux)
MatriceStyleNormal(0, NbParagraphesNormaux) = Titre1EnCours
MatriceStyleNormal(1, NbParagraphesNormaux) = I
NbParagraphesNormaux = NbParagraphesNormaux + 1
Case StyleQuechua
ReDim Preserve MatriceStyleQuechua(1, NbParagraphesQuechua)
MatriceStyleQuechua(0, NbParagraphesQuechua) = Titre1EnCours
MatriceStyleQuechua(1, NbParagraphesQuechua) = I
NbParagraphesQuechua = NbParagraphesQuechua + 1
End Select
Next I
End With
Set DocCible = Documents.Add
With DocCible
For I = LBound(MatriceDesTitres, 2) To UBound(MatriceDesTitres, 2)
Set MonRangeTitre = DocSource.Paragraphs(MatriceDesTitres(1, I)).Range
MonRangeTitre.Copy
.Paragraphs.Add
With Selection
.Paste
.MoveUp unit:=wdLine, Count:=1
.EndKey unit:=wdLine, Extend:=wdExtend
.Style = StyleQuechua
.MoveDown unit:=wdLine, Count:=1
'MsgBox .Range.Text
End With
For J = LBound(MatriceStyleQuechua, 2) To UBound(MatriceStyleQuechua, 2)
If MatriceStyleQuechua(0, J) = MatriceDesTitres(0, I) Then
Set MonRangeCible = DocSource.Paragraphs(MatriceStyleQuechua(1, J)).Range
MonRangeCible.Copy
.Paragraphs.Add
Selection.Paste
Set MonRangeCible = Nothing
End If
Next J
MonRangeTitre.Copy
.Paragraphs.Add
Selection.Paste
For J = LBound(MatriceStyleNormal, 2) To UBound(MatriceStyleNormal, 2)
If MatriceStyleNormal(0, J) = MatriceDesTitres(0, I) Then
Set MonRangeCible = DocSource.Paragraphs(MatriceStyleNormal(1, J)).Range
MonRangeCible.Copy
.Paragraphs.Add
Selection.Paste
Set MonRangeCible = Nothing
End If
Next J
Set MonRangeTitre = Nothing
Next I
End With
Set DocCible = Nothing
Set DocSource = Nothing
End Sub |
Partager