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
|
Sub Test2()
Dim DocEnCours As Document, NouveauDoc As Document
Dim MatriceRanges() As Variant
Dim I As Long, IndexMatrice As Long, CaractereDebut As Long
Dim StrFilename As String
Set DocEnCours = ActiveDocument
With DocEnCours
IndexMatrice = 0
CaractereDebut = 1
StrFilename = "AAA"
For I = 1 To .Paragraphs.Count
If InStr(1, .Paragraphs(I).Range, "///", vbTextCompare) > 0 Then
.Paragraphs(I - 1).Range.Select
Selection.EndKey unit:=wdLine
Selection.HomeKey unit:=wdStory, Extend:=wdExtend
ReDim Preserve MatriceRanges(1, IndexMatrice)
MatriceRanges(1, IndexMatrice) = Selection.Characters.Count
If IndexMatrice > 0 Then
MatriceRanges(0, IndexMatrice) = CaractereDebut
End If
.Paragraphs(I + 1).Range.Select
Selection.HomeKey unit:=wdLine
Selection.HomeKey unit:=wdStory, Extend:=wdExtend
CaractereDebut = Selection.Characters.Count
IndexMatrice = IndexMatrice + 1
End If
Next I
For IndexMatrice = LBound(MatriceRanges, 2) To UBound(MatriceRanges, 2)
' Recherche du 1er caractère
Selection.HomeKey unit:=wdStory, Extend:=wdExtend
Selection.SetRange MatriceRanges(0, IndexMatrice), MatriceRanges(1, IndexMatrice)
Selection.Range.Copy
Set NouveauDoc = Documents.Add
With NouveauDoc
.Range.Paste
.SaveAs ThisDocument.Path & "\" & StrFilename & Format(IndexMatrice + 1, "000")
.Close True
End With
Set NouveauDoc = Nothing
Next IndexMatrice
End With
Set DocEnCours = Nothing
End Sub |
Partager