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
|
Option Explicit
Sub RechercheDansTableauWord(ByVal DocEnCours As Document, ByVal ChainesRecherchees As Variant)
Dim CelluleEnCours As Cell
Dim MesCellules As Cells
Dim I As Integer, J As Integer, PositionChaine As Integer
Dim Text1 As String, Text2 As String
With DocEnCours
For I = 1 To .Tables.Count
.Tables(I).Select
Set MesCellules = Selection.Cells
For Each CelluleEnCours In MesCellules
For J = LBound(ChainesRecherchees) To UBound(ChainesRecherchees)
PositionChaine = InStr(1, CelluleEnCours.Range.Text, ChainesRecherchees(J), vbTextCompare)
If PositionChaine > 0 Then
With CelluleEnCours.Range
Text1 = Mid(.Text, 1, PositionChaine + Len(ChainesRecherchees(J)) - 1)
Text2 = Mid(.Text, PositionChaine + Len(ChainesRecherchees(J)))
.Font.ColorIndex = wdRed
.Text = Text1 & "#" & Text2
End With
End If
Next J
Next CelluleEnCours
Set MesCellules = Nothing
Next I
End With
End Sub
Sub TestRechercheDansTableauWord()
Dim DocumentWordInstance As Document
Dim MesChainesAChercher As Variant
Set DocumentWordInstance = ActiveDocument
MesChainesAChercher = Array("A1-131", "A1-132")
With DocumentWordInstance
If .Tables.Count > 0 Then
RechercheDansTableauWord DocumentWordInstance, MesChainesAChercher
End If
End With
Set DocumentWordInstance = Nothing
End Sub |
Partager