PDA

View Full Version : [SOLVED:] PowerPoint change table cell fill and font color



StarPig
01-05-2019, 01:49 PM
Hello, I am having a problem with my code below.

In a Table in PowerPoint, the user clicks or selects table cells and this VBA shades the background of the cell(s) gray.

I need it to have blue text RGB(0,100,200) and a white border of 3 pt around the cell(s).

It works perfect apart from blue text and white borders. Grateful for your help. Thank you.


Public Sub GrayCell()


Dim X As Integer
Dim Y As Integer
Dim oTbl As Table


Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table


For X = 1 To oTbl.Columns.Count
For Y = 1 To oTbl.Rows.Count


With oTbl.Cell(Y, X)


If .Selected <> False Then 'Strange bug - will ignore if statement entirely if you use "= True"
'Debug.Print "Test worked " & Now


.Shape.Fill.ForeColor.RGB = RGB(211,211,211)
End If
End With
Next 'y
Next 'x
End Sub

John Wilson
01-08-2019, 02:52 AM
Sub BlueCell()
Dim X As Integer
Dim Y As Integer
Dim oTbl As Table
Dim B As Long
Set oTbl = ActiveWindow.Selection.ShapeRange(1).Table
For X = 1 To oTbl.Columns.Count
For Y = 1 To oTbl.Rows.Count
With oTbl.Cell(Y, X)
If .Selected Then
.Shape.Fill.ForeColor.RGB = RGB(0, 100, 200)
For B = 1 To 4 ' top,left,bottom and right
With .Borders(B)
.Visible = msoTrue
.ForeColor.RGB = vbWhite
.Weight = 3
End With
Next B
End If
End With
Next 'y
Next 'x
End Sub

RayKay
01-08-2019, 06:07 AM
Great. Is there a line to make the font a chosen colour? I.e.:

.Shape.Fill.TextRange.Font.Color.RGB = RGB(211,211,211)

I tried this line but it failed :(

Thank you.

John Wilson
01-08-2019, 06:58 AM
It would be
.Shape.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(211, 211, 211)