#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
Thank you for the help John and so quickly too! It works perfectly!
|
#4
|
|||
|
|||
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!
|
#5
|
|||
|
|||
Change this line
Code:
.TextFrame.TextRange.Font.Color.RGB = RGB(255, 0, 0) Code:
.Fill.Forecolor.RGB = RGB(255, 0, 0) |
Tags |
vba change color, vba powerpoint |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Changing color of instructional text in a content control box | Document Specialist | Word | 2 | 08-17-2018 05:25 AM |
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 |
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 |