Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-21-2016, 04:09 PM
lifelessons lifelessons is offline Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Windows 10 Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Office 2010 64bit
Novice
Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables
 
Join Date: Jun 2016
Posts: 2
lifelessons is on a distinguished road
Default Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables

Hi all,

i am trying to write a VBA code to basically replace all instances of BLUE font in my power point and replace it with blanks/underscores.

so even if in a textbox/tablecell there're other colored fonts, it will replace only the BLUE ones.

So far it works perfectly fine with my textboxes, but i'm having trouble with the tablecells part. it only replaces if the ENTIRE cell is blue font. i can't get it to work like the textboxes.



this is my code... pardon the formatting, i'm just really bad at coding.

////
Sub delblue()
Dim oSld As Slide
Dim oShp As Shape
Dim x As Long
Dim i As Long
Dim j As Long


For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
With oShp.TextFrame.TextRange
For x = .Runs.Count To 1 Step -1
If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Then
.Runs(x).Text = "_____________"
.Runs(x).Font.Subscript = msoFalse
.Runs(x).Font.Superscript = msoFalse
End If
Next x
End With
End If 'has text

End If 'has textframe

If oShp.HasTable Then

For i = 1 To oShp.Table.Rows.Count
For j = 1 To oShp.Table.Columns.Count


If oShp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.T extRange.Font.Color.RGB = RGB(0, 0, 255) Then
oShp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.T extRange.Text = " "
oShp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.T extRange.Font.Subscript = msoFalse
oShp.Table.Rows.Item(i).Cells(j).Shape.TextFrame.T extRange.Font.Superscript = msoFalse


End If
Next j
Next i
End If
Next oShp
Next oSld
End Sub

////


would really appreciate any help here.. i've been stuck on this for days.. the ppt file that i have is just really huge and has many slides, so having this code will definitely help the processing time.
Attached Images
File Type: jpg before.JPG (66.2 KB, 14 views)
File Type: jpg after notice the blue font in the left cell was not replaced.JPG (57.5 KB, 14 views)
Reply With Quote
  #2  
Old 06-22-2016, 12:10 AM
JohnWilson JohnWilson is offline Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Windows 7 64bit Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,913
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

See if this gets you started

Code:
Sub delblue()
   Dim oSld As Slide
   Dim oShp As Shape
   Dim x As Long
   Dim l As Long
   Dim i As Long
   Dim j As Long
   Dim otr As TextRange

   For Each oSld In ActivePresentation.Slides
      For Each oShp In oSld.Shapes
         If oShp.HasTextFrame Then
            If oShp.TextFrame.HasText Then
               With oShp.TextFrame.TextRange
                  For x = .Runs.Count To 1 Step -1
                     If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Then
                        Set otr = .Runs(x)
                        For l = 1 To otr.Length
                           otr.Characters(l) = "_"
                           otr.Font.Color.RGB = RGB(120, 120, 120)
                        Next l
                        .Runs(x).Font.Subscript = msoFalse
                        .Runs(x).Font.Superscript = msoFalse
                     End If
                  Next x
               End With
            End If      'has text
         End If      'has textframe
         If oShp.HasTable Then
            For i = 1 To oShp.Table.Rows.Count
               For j = 1 To oShp.Table.Columns.Count
                  If oShp.Table.Cell(i, j).Shape.TextFrame.HasText Then
                     With oShp.Table.Cell(i, j).Shape.TextFrame.TextRange
                        For x = .Runs.Count To 1 Step -1
                           If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Then
                              Set otr = .Runs(x)
                              For l = 1 To otr.Length
                                 otr.Characters(l) = "_"
                                 otr.Font.Color.RGB = RGB(120, 120, 120)
                              Next l
                              .Runs(x).Font.Subscript = msoFalse
                              .Runs(x).Font.Superscript = msoFalse
                           End If
                        Next x
                     End With
                    End If
                  Next j
               Next i
            End If
         Next oShp
      Next oSld
   End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials

Last edited by JohnWilson; 06-22-2016 at 11:45 PM.
Reply With Quote
  #3  
Old 06-23-2016, 06:40 PM
lifelessons lifelessons is offline Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Windows 10 Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Office 2010 64bit
Novice
Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables
 
Join Date: Jun 2016
Posts: 2
lifelessons is on a distinguished road
Default

hi john,

thanks for your reply! i like it that the code changes the font to gray color as well.

there's a small issue, when there's a line break in the cell like

"numbers
123"

the word "numbers" get replaced by a "__" but the numbers "123" doesn't. it only gets grayed out.

and when running the code, powerpoint goes into "not responding" mode, but it becomes fine again after a while.

i'll try tweaking the code to see if i can incorporate yours into the one i currently have.

thanks!
Reply With Quote
  #4  
Old 06-24-2016, 12:17 AM
JohnWilson JohnWilson is offline Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Windows 7 64bit Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Office 2010 32bit
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,913
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

This would help but if you have equations they follow different rules and you may get unexpected results

Code:
Sub delblue()
   Dim oSld As Slide
   Dim oShp As Shape
   Dim x As Long
   Dim l As Long
   Dim i As Long
   Dim j As Long
   Dim otr As TextRange
   Dim otrTotal As TextRange

   For Each oSld In ActivePresentation.Slides
      For Each oShp In oSld.Shapes
         If oShp.HasTextFrame Then
            If oShp.TextFrame.HasText Then
               With oShp.TextFrame.TextRange
                  For x = .Runs.Count To 1 Step -1
                     If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Then
                        Set otr = .Runs(x)
                        For l = 1 To otr.Length
                            If otr.Characters(l).Font.Color.RGB = RGB(0, 0, 255) Then otr.Characters(l) = "_"
                           If otr.Characters(l) = "_" Then otr.Characters(l).Font.Color.RGB = RGB(120, 120, 120)
                        Next l
                        .Runs(x).Font.Subscript = msoFalse
                        .Runs(x).Font.Superscript = msoFalse
                     End If
                  Next x
               End With
            End If      'has text
         End If      'has textframe
         If oShp.HasTable Then
            For i = 1 To oShp.Table.Rows.Count
               For j = 1 To oShp.Table.Columns.Count
                  If oShp.Table.Cell(i, j).Shape.TextFrame.HasText Then
                  Set otrTotal = oShp.Table.Cell(i, j).Shape.TextFrame.TextRange
                     With otrTotal
                        For x = .Runs.Count To 1 Step -1
                           If .Runs(x).Font.Color.RGB = RGB(0, 0, 255) Then
                              Set otr = .Runs(x)
                              For l = 1 To otr.Length
                              If otrTotal.Paragraphs.Count > 1 Then
                              If Asc(otr.Characters(l)) = 13 Then
                              otr.Characters(l) = vbCrLf
                               Else
                                otr.Characters(l) = "_"
                                 If otr.Characters(l) = "_" Then otr.Characters(l).Font.Color.RGB = RGB(120, 120, 120)
                               End If
                               Else
                                If otr.Characters(l).Font.Color.RGB = RGB(0, 0, 255) Then otr.Characters(l) = "_"
                                 If otr.Characters(l) = "_" Then otr.Characters(l).Font.Color.RGB = RGB(120, 120, 120)
                               End If
                              Next l
                              .Runs(x).Font.Subscript = msoFalse
                              .Runs(x).Font.Superscript = msoFalse
                           End If
                        Next x
                     End With
                    End If
                  Next j
               Next i
            End If
         Next oShp
      Next oSld
   End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
Reply

Tags
powerpointvba, pptvba, replacefont



Similar Threads
Thread Thread Starter Forum Replies Last Post
Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Does anyone know how to remove breaks between tables? chrisd2000 Word Tables 18 07-02-2014 02:48 PM
Powerpoint VBA to remove/replace/delete certain colored font in textbox and in tables Codes for Word Textbox Font Color? tinfanide Word VBA 7 10-23-2012 03:13 PM
changing default font for new textbox? dylansmith PowerPoint 3 10-18-2012 11:12 AM
PowerPoint 2007 Textbox Lock / Form Issues LTechie12 PowerPoint 0 01-08-2012 02:08 PM
Printing in white data in a colored PowerPoint 2007 Chart bigbizz PowerPoint 0 08-29-2011 07:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft