Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-28-2019, 10:49 AM
derridascat derridascat is offline VBA - Changing color of text in a single column of a table Windows 10 VBA - Changing color of text in a single column of a table Office 2016
Novice
VBA - Changing color of text in a single column of a table
 
Join Date: Apr 2019
Posts: 3
derridascat is on a distinguished road
Default VBA - Changing color of text in a single column of a table

Hey all,

I'm looking to write a VBA macro that searches the first column of all my tables in powerpoint, and switches a specific text to a different color. I.E. I'd like all my tables that have "Yes" in the first column to switch the text "Yes" to a different color then black font, as doing it manually is going to take a bit of time. Here's what I got so far, but I can't get figure out how to specify the first column only. Appreciate the help!


Option Explicit

Sub ChangeTextColors()



Dim oSl As Slide
Dim oSh As Shape
Dim lCol As Long
Dim lRow As Long
Dim x As Long


For Each oSl In ActivePresentation.Slides
For Each oSh In oSl.Shapes

If oSh.HasTable Then
With oSh.Table
For lCol = 1 To .Columns.Count
For lRow = 1 To .Rows.Count
With .Cell(lRow, lCol).Shape
If .HasTextFrame Then
If .TextFrame.HasText Then
If .TextFrame.TextRange = "YES" Then
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0)
End If
End If
End If
End With
Next
Next
End With
End If

Next
Next

End Sub
Reply With Quote
  #2  
Old 04-28-2019, 11:25 AM
JohnWilson JohnWilson is offline VBA - Changing color of text in a single column of a table Windows 10 VBA - Changing color of text in a single column of a table Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

This should do it:

Code:
Sub ChangeTextColors()

Dim oSl As Slide
Dim oSh As Shape
Dim lRow As Long

For Each oSl In ActivePresentation.Slides
For Each oSh In oSl.Shapes
If oSh.HasTable Then
With oSh.Table
For lRow = 1 To .Rows.Count
With .Cell(lRow, 1).Shape
If .HasTextFrame Then
If .TextFrame.HasText Then
If UCase(.TextFrame.TextRange) = "YES" Then
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0)
End If
End If
End If
End With
Next lRow
End With
End If
Next oSh
Next oSl
End Sub
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
  #3  
Old 04-28-2019, 11:28 AM
derridascat derridascat is offline VBA - Changing color of text in a single column of a table Windows 10 VBA - Changing color of text in a single column of a table Office 2016
Novice
VBA - Changing color of text in a single column of a table
 
Join Date: Apr 2019
Posts: 3
derridascat is on a distinguished road
Default

Thank you for the help John and so quickly too! It works perfectly!
Reply With Quote
  #4  
Old 05-08-2019, 11:14 AM
derridascat derridascat is offline VBA - Changing color of text in a single column of a table Windows 10 VBA - Changing color of text in a single column of a table Office 2016
Novice
VBA - Changing color of text in a single column of a table
 
Join Date: Apr 2019
Posts: 3
derridascat is on a distinguished road
Default Additional Question

I had another question related to this if anybody could offer some help. I'm looking to modify the code to change the shading of the cell rather than the color of the font and was wondering if there was an easy fix for that. Appreciate the help for the VBA beginner! Thanks!
Reply With Quote
  #5  
Old 05-09-2019, 02:47 AM
JohnWilson JohnWilson is offline VBA - Changing color of text in a single column of a table Windows 10 VBA - Changing color of text in a single column of a table Office 2016
Programmer
 
Join Date: Nov 2008
Location: UK
Posts: 1,912
JohnWilson has a spectacular aura aboutJohnWilson has a spectacular aura about
Default

Change this line

Code:
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0)
To This

Code:
.Fill.Forecolor.RGB = RGB(255, 0, 0)
__________________
Microsoft PowerPoint MVP 2007-2023
Free Advanced PowerPoint Tips and Tutorials
Reply With Quote
Reply

Tags
vba change color, vba powerpoint

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - Changing color of text in a single column of a table Changing color of instructional text in a content control box Document Specialist Word 2 08-17-2018 05:25 AM
VBA - Changing color of text in a single column of a table VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color jc491 Word VBA 8 09-30-2015 06:10 AM
VBA - Changing color of text in a single column of a table documents saved with double column revert to single column when re-opened danw Word 6 04-08-2015 06:24 AM
How can I temporarily break a 3 column format in order to type a single column paragraph William P Word 1 01-04-2015 06:40 PM
Changing the color of the last column in a chart changes the legend met0813 PowerPoint 0 01-03-2014 09:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:45 AM.


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