Search code examples
vbaoffice365powerpoint

Changing Font Outline color inside a Table Cell with VBA using Application.CommandBar.ExecuteMSO


Win10x64 Office 365 PPT v 16.0.12325.202080 64-bits

I need to show a character with a yellow font color but a black outline, for readability purposes. This character goes inside a Powerpoint table Cell.

The following link has a method that I'm currently using that consists of creating a dummy shape, adding text to it, modify the shape's textframe2 textrange font line properties and then copying it and pasting it back to the table cell.

http://www.vbaexpress.com/forum/archive/index.php/t-43787.html

This was asked 8 years ago, but I'm currently seeing the same behaviour where we can't directly manipulate the textframe2 wordart format of text inside a cell. The program doesn't show an error but doesn't work.

I have given up on trying to modify the textrame2 textrange font line properties directly from VBA.

I have managed to get it to activate the font outline color using Application.CommandBars.ExecuteMso ("TextOutlineColorPicker")

After it's activated I thought I could modify the textframe2 textrange font line properties, but it still doesn't work.

Is there an Application.CommandBars idMso for changing the font outline color and font outline line width inside a table cell?

Or another other than pasting the formatted text inside a table cell.

Edit: Adding an image to illustrate what I mean by text color and text outline color and the menu used to show them in red circle:

enter image description here

Edit2 Added another snapshot to exemplify a character inside a cell with black outline and a character inside a cell without an outline enter image description here

Thanks


Solution

  • Here's an example to access a Table on a given slide and change one cell's attributes. The example slide I'm using looks like this

    enter image description here

    The code itself creates a function that allows you to select a table from a particular slide, and a single cell within the table and highlight it.

    Option Explicit
    
    Sub test()
        HighlightTableCell 1, 2, 3
    End Sub
    
    Sub HighlightTableCell(ByVal slideNumber As Long, _
                           ByVal thisRow As Long, _
                           ByVal thisCol As Long)
        Dim theSlide As Slide
        Set theSlide = ActivePresentation.Slides(slideNumber)
    
        Dim shp As Shape
        For Each shp In theSlide.Shapes
            If shp.Type = msoTable Then
                Dim theTable As Table
                Set theTable = shp.Table
                With theTable.Cell(thisRow, thisCol)
                    With .Shape.TextFrame2.TextRange.Characters.Font.Fill
                        .Visible = msoTrue
                        .ForeColor.RGB = RGB(255, 255, 0)
                        .Transparency = 0
                        .Solid
                    End With
                    With .Shape.TextFrame2.TextRange.Characters.Font.Line
                        .Visible = msoTrue
                        .ForeColor.ObjectThemeColor = msoThemeColorText1
                        .ForeColor.TintAndShade = 0
                        .ForeColor.Brightness = 0
                        .Transparency = 0
                    End With
                End With
            End If
        Next shp
    End Sub