Consulting

Results 1 to 4 of 4

Thread: PowerPoint change table cell fill and font color

  1. #1
    VBAX Regular
    Joined
    Dec 2018
    Posts
    24
    Location

    PowerPoint change table cell fill and font color

    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
    Last edited by StarPig; 01-05-2019 at 03:03 PM.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Contributor
    Joined
    Dec 2018
    Location
    South London
    Posts
    115
    Location
    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.

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    It would be
    .Shape.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(211, 211, 211)
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

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
  •