Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2572
  • Last Modified:

Format a Cell in a Table Shape in PowerPoint 2007

In the absence of PowerPoint 2007 Macro Recorder, how do you format a table cell's background to be Red with White Centered Text with Calibri 8pt Font?  I tried using Word 2007 VBA code but it does not appear to be the same.

CowboyWM
0
cowboywm
Asked:
cowboywm
  • 3
1 Solution
 
Rgonzo1971Commented:
i,

pls try

Sub Macro()
Set PPTSlide = ActivePresentation.Slides(1)

Set objTable = PPTSlide.Shapes.AddTable(3, 4, 10, 10, 288, 216)
With objTable.Table.Columns(1).Cells(1).Shape
.Fill.ForeColor.RGB = 255
.TextFrame.TextRange.Font.Color = vbWhite
.TextFrame.TextRange.Font.Name = "Calibri"
.TextFrame.TextRange.Font.Size = 8
.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
End With
End Sub

Open in new window

Regards
0
 
cowboywmAuthor Commented:
Not looking for a new table to be inserted into the current slide.  I already have a table with 6 columns and 6 rows.  If I position my cursor in any cell, I want the macro to change the background to be Red with White Centered Text with Calibri 8pt Font.
0
 
Rgonzo1971Commented:
Hi,

pls try
Sub Macro()

With ActiveWindow.Selection
    With .TextRange
        .Font.Color = vbWhite
        .Font.Name = "Calibri"
        .Font.Size = 8
        .ParagraphFormat.Alignment = ppAlignCenter
    End With
    If .ShapeRange(1).Type = msoTable Then
        Set oTbl = .ShapeRange(1).Table
        For x = 1 To oTbl.Columns.Count
            For y = 1 To oTbl.Rows.Count
                If oTbl.Cell(x, y).Selected Then
                    With oTbl.Cell(x, y).Shape
                        .Fill.ForeColor.RGB = 255
                    End With
                End If
            Next
        Next
    End If
End With

End Sub

Open in new window

Regards
0
 
JSRWilsonCommented:
Did you check the code of a non square table?? Say 8 x 3.
0
 
Rgonzo1971Commented:
Hi

@ JSRWilson  Tks I forgot it is like in Excel : Cell(row, column)

Corrected version
Sub Macro()

With ActiveWindow.Selection
    With .TextRange
        .Font.Color = vbWhite
        .Font.Name = "Calibri"
        .Font.Size = 8
        .ParagraphFormat.Alignment = ppAlignCenter
    End With
    If .ShapeRange(1).Type = msoTable Then
        Set oTbl = .ShapeRange(1).Table
        For x = 1 To oTbl.Columns.Count
            For y = 1 To oTbl.Rows.Count
                If oTbl.Cell(y, x).Selected Then
                    With oTbl.Cell(y, x).Shape
                        .Fill.ForeColor.RGB = 255
                    End With
                End If
            Next
        Next
    End If
End With

End Sub

Open in new window

Regards
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now