PDA

View Full Version : [SOLVED:] Replace every number with an X



RayKay
01-10-2024, 09:08 AM
Hi all

I've the following code, but it only replaces numbers in text boxes to an X. I can't find a way for this to change numbers within tables and charts, to an X - it only changes in text boxes. Any advice please? Thank you.




Sub AllNumbersAreX()


Dim fnd As Variant
Dim rplc As Variant
Dim NumberArray As Variant
Dim TxtRng As TextRange
Dim TmpRng As TextRange
Dim sld As Slide
Dim shp As Shape


'Find/Replace Variables
NumberArray = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
rplc = "x"

'Loop Through Each Slide
For Each sld In ActivePresentation.Slides
For y = LBound(NumberArray) To UBound(NumberArray)
For Each shp In sld.Shapes


fnd = NumberArray(y)

If shp.HasTextFrame Then
If shp.TextFrame.HasText Then

Set TxtRng = shp.TextFrame.TextRange

Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False)

End If
End If

'Replace Other Instances (if necessary)
Do While Not TmpRng Is Nothing
Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False)
Loop


Next shp
Next y
Next sld

MsgBox "All text and chart numbers are now X"


End Sub

Aussiebear
01-10-2024, 05:07 PM
Just wondering if you are delving deep enough with the code to find the charts.



Maybe starting here with


For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasChart Then
.... your code to alter the data