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
| Sub ReplaceSpace(ToBeReplaced As String, Replaceby As String)
Dim sld As Slide
Dim grpItem As Shape
Dim shp As Shape
Dim i As Long
Dim j As Long
Dim NbRemp As Long
Dim iCar As Long
Dim NbCarToBeReplaced As Long
Dim myPos As Long
Dim foundText As Variant
Dim txt_r As String
NbRemp = 0
iCar = 1
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
txt_r = shp.TextFrame.TextRange.Text
Set foundText = shp.TextFrame.TextRange.Find(FindWhat:=ToBeReplaced, WholeWords:=msoFalse)
Do While Not (foundText Is Nothing)
NbCar = shp.TextFrame.TextRange.Characters.Count
NbCarToBeReplaced = Len(ToBeReplaced)
Do While iCar <= NbCar
myPos = InStr(iCar, txt_r, ToBeReplaced)
If myPos > 0 Then
iCar = myPos + NbCarToBeReplaced + 1
NbRemp = NbRemp + 1
Else: Exit Do
End If
Loop
Set foundText = shp.TextFrame.TextRange.Replace(FindWhat:=ToBeReplaced, replacewhat:=Replaceby, WholeWords:=msoFalse)
' passer au suivant
Set foundText = shp.TextFrame.TextRange.Find(FindWhat:=ToBeReplaced, WholeWords:=msoFalse)
Loop
End If
If shp.HasTable Then
For i = 1 To shp.Table.Rows.Count
For j = 1 To shp.Table.Columns.Count
txt_r = shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Text
Set foundText = shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Find(FindWhat:=ToBeReplaced, WholeWords:=msoFalse)
Do While Not (foundText Is Nothing)
NbCar = shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Characters.Count
NbCarToBeReplaced = Len(ToBeReplaced)
Do While iCar <= NbCar
myPos = InStr(iCar, txt_r, ToBeReplaced)
If myPos > 0 Then
iCar = myPos + NbCarToBeReplaced + 1
NbRemp = NbRemp + 1
Else: Exit Do
End If
Loop
Set foundText = shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Replace(FindWhat:=ToBeReplaced, replacewhat:=Replaceby, WholeWords:=msoFalse)
' passer au suivant
Set foundText = shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Find(FindWhat:=ToBeReplaced, WholeWords:=msoFalse)
Loop
Next j
Next i
End If
If shp.Type = msoGroup Or shp.Type = 24 Then
For g = 1 To shp.GroupItems.Count
txt_r = shp.GroupItems(g).TextFrame.TextRange.Text
Set foundText = shp.GroupItems(g).TextFrame.TextRange.Find(FindWhat:=ToBeReplaced, WholeWords:=msoFalse)
Do While Not (foundText Is Nothing)
NbCar = shp.GroupItems(g).TextFrame.TextRange.Characters.Count
NbCarToBeReplaced = Len(ToBeReplaced)
Do While iCar <= NbCar
myPos = InStr(iCar, txt_r, ToBeReplaced)
If myPos > 0 Then
iCar = myPos + NbCarToBeReplaced + 1
NbRemp = NbRemp + 1
Else: Exit Do
End If
Loop
Set foundText = shp.GroupItems(g).TextFrame.TextRange.Replace(FindWhat:=ToBeReplaced, replacewhat:=Replaceby, WholeWords:=msoFalse)
' passer au suivant
Set foundText = shp.GroupItems(g).TextFrame.TextRange.Find(FindWhat:=ToBeReplaced, WholeWords:=msoFalse)
Loop
Next g
End If
Next shp
Next sld
MsgBox NbRemp & " remplacements"
End Sub
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Sub ReplaceAll(ToBeReplaced As String, Replaceby As String)
Dim sld As Slide
Dim grpItem As Shape
Dim shp As Shape
Dim i As Long
Dim j As Long
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, ToBeReplaced, Replaceby)
End If
End If
If shp.HasTable Then
For i = 1 To shp.Table.Rows.Count
For j = 1 To shp.Table.Columns.Count
shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Text = _
Replace(shp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.TextRange.Text, ToBeReplaced, Replaceby)
Next j
Next i
End If
If shp.Type = msoGroup Or shp.Type = 24 Then
For g = 1 To shp.GroupItems.Count
If shp.GroupItems(g).HasTextFrame Then
If shp.GroupItems(g).TextFrame.HasText Then
shp.GroupItems(g).TextFrame.TextRange.Text = Replace(shp.GroupItems(g).TextFrame.TextRange.Text, ToBeReplaced, Replaceby)
End If
End If
Next g
End If
Next shp
Next
End Sub |
Partager