formating a PowerPoint table

smig

Registered User.
Local time
Today, 09:08
Joined
Nov 25, 2009
Messages
2,209
I'm using VB code to create a table in PowerPoint, using the PowerPoint object.

Most of it is going well. I create the table and put the data in the cells.
My problem is I can't find a way to format the Font size for the entire table. I can format it cell by cell but this is very slow proccess.

Thanks,
Tal
 
You're asking in the wrong section of the forum smig. Can the entire table be formatted manually in Power Point?
 
You're asking in the wrong section of the forum smig
Why is it so?
this is a code related question. I want it to be done by Access VBA code

Can the entire table be formatted manually in Power Point?
sure. no problem.
not even required to select the text in the table. selecting the table is enough.
 
This is an Access VBA section of the forum and what you need is an PowerPoint VBA solution. You will get a better response in the appropriate section.

Let me see the code you use to format a cell.
 
Code:
Public Sub CreatePPT()
' On Error GoTo ErrHere

Dim db As Database
Dim rsMigzarim As Recordset
Dim rs As Recordset
Dim pptObj As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Dim pptSlide As Slide
Dim lngX As Long
Dim lngY As Long
Dim lngShapeID As Long
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * From [SumStatusGius] ORDER BY [Table1]", dbOpenDynaset)
Set rsMigzarim = db.OpenRecordset("SELECT [FieldName] From [Table2] ORDER BY [SortID]", dbOpenDynaset)
Set pptObj = New PowerPoint.Application
Set pptPres = pptObj.Presentations.Add
lngX = 1
lngY = 1
lngShapeID = 2
With pptPres
    With .Slides.Add(pptPres.Slides.Count + 1, ppLayoutTitle)
        .Shapes.AddTable 23, 20, 230, 60
        
        lngShapeID = lngShapeID + 1
        With .Shapes(lngShapeID).Table
            .Columns(1).Width = 60
            .Columns(2).Width = 34
            .Columns(3).Width = 34
            .Columns(4).Width = 34
            .Columns(5).Width = 34
            .Columns(6).Width = 34
            .Columns(7).Width = 34
            .Columns(8).Width = 34
            .Columns(9).Width = 34
            .Columns(10).Width = 34
            .Columns(11).Width = 34
            .Columns(12).Width = 34
            .Columns(13).Width = 34
            .Columns(14).Width = 34
            .Columns(15).Width = 34
            .Columns(16).Width = 34
            .Columns(17).Width = 34
            .Columns(18).Width = 34
            .Columns(19).Width = 34
            .Columns(20).Width = 34
            
            lngX = 1
            lngY = 1
            rsMigzarim.MoveFirst
            While Not rsMigzarim.EOF
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = rsMigzarim.Fields("Migzar").Value
                rsMigzarim.MoveNext
            Wend
            lngX = lngX + 1
            .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = "Name"
            
            While Not rs.EOF
                lngX = 1
                lngY = lngY + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = rs.Fields("FieldName").Value
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("11").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("12").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("13").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("14").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("15").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("16").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("17").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("21").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("22").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("23").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("31").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("32").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("33").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("41").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("51").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("61").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("62").Value, "")
                lngX = lngX + 1
                .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("63").Value, "")
                lngX = lngX + 1
                 .Cell(lngY, lngX).Shape.TextFrame.TextRange.Text = Nz(rs.Fields("FieldSum").Value, "")
                lngX = lngX + 1
               
                
                
                
                rs.MoveNext
            Wend
            
            
[COLOR=darkred]' -- Format cells        
            For lngY = 1 To 23
                For lngX = 1 To 20
                    .Cell(lngY, lngX).Shape.TextFrame.TextRange.Characters.Font.Size = 9
                    .Cell(lngY, lngX).Shape.TextFrame.TextRange.Characters.Font.Bold = msoFalse
                Next lngX
            Next lngY
[/COLOR]        
               
        
        
        End With
    End With
End With
 
ExitHere:
    MsgBox "end"
    Exit Sub
ErrHere:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitHere
End Sub
 
I've had a look and it seems it can only be done Cell by Cell. If I think of a way I will let you know but in the meantime ask in a Powerpoint VBA forum.
 
The only way I can think of at the moment is to perform your formatting in Excel and paste it in Powerpoint. If you're already exporting from Excel then this option may suffice.

Perhaps it was for this reason TableStyles was added to 2007 PP.
 
I'm using PP 2010

How do I create my oun TableStyle ?
 
I'm using PP 2010

How do I create my oun TableStyle ?
I don't think you can. You can ask the Powerpoint VBA experts but from what I've read briefly it's indicative that it can't be done in PowerPoint.

After reading this http://www.pptfaq.com/FAQ00790_Working_with_PowerPoint_tables.htm it seems formating each cell is the only way to go :mad:

I tried to run the code from PwerPoint (without data) and it seems to run much much faster.
Is there any way to connect PP to Access to read the data ?

Tal
Yep, looks like it.

In that case, why not format it first, then set the value.

You have DAO and ADODB in VBA so you can use one of those libraries.
 
You have to do it cell by cell, just after you write data to cell format the table cell.

.Cell(lngY, lngX).Shape.TextFrame.TextRange.Font.Size = 10 '10pt font
.Cell(lngY, lngX).Shape.TextFrame.TextRange.Font.Bold = msoFalse 'make it NOT bold
 

Users who are viewing this thread

Back
Top Bottom