Consulting

Results 1 to 2 of 2

Thread: Replace every number with an X

  1. #1
    VBAX Contributor
    Joined
    Dec 2018
    Location
    South London
    Posts
    115
    Location

    Replace every number with an X

    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

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    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
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •