PDA

View Full Version : [SOLVED:] [ask] Change text format in imported excel table to all slides in PPT 2010



qiyusi
12-08-2014, 09:49 PM
Hello All,

Newbie here. This is my first post.

I have problem about how to create Vba for my Powerpoint file.
here's the situation:

i Copy pasted excel table containing text to powerpoint.

what i want to have is:
- change all text size to 9
- change all align to left

that will apply to any tables on any slides on whole powerpoint file.
i can't do this manualy one by one, as there will be many slides.
attached the file example.
try to write the code, but i am new to vba, not sure what to write.

how to complete the code below?

sub changetext ()
For Each sld In ActivePresentation.Slides
For Each sh In sld.Shapes

.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft
.TextFrame.TextRange.Font.Size = 9

Next
Next
end sub

is anyone can solve my problem?

thanks before.

John Wilson
12-09-2014, 01:17 AM
See it this works


Sub FixXL()
Dim oshp As Shape
Dim osld As Slide
Dim otbl As Table
Dim iRow As Integer
Dim iCol As Integer
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTable Then
Set otbl = oshp.Table
For iRow = 1 To otbl.Rows.Count
For iCol = 1 To otbl.Columns.Count
otbl.Cell(iRow, iCol).Shape.TextFrame.TextRange.Font.Size = 9
Next iCol
Next iRow
End If
Next oshp
Next osld
End Sub

qiyusi
12-09-2014, 01:27 AM
That's amazingly works!
You're trully Master!
many thanks. you saved my day :)

anyway, is it different code if want to apply to text box / shapes?

John Wilson
12-09-2014, 01:38 AM
As written it apply only to tables (which pasted tables from XL will be)

To change tables, shapes, and textboxes but not placeholders


Dim oshp As Shape
Dim osld As Slide
Dim otbl As Table
Dim iRow As Integer
Dim iCol As Integer
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
'Is it a table
If oshp.HasTable Then 'YES
Set otbl = oshp.Table
For iRow = 1 To otbl.Rows.Count
For iCol = 1 To otbl.Columns.Count
otbl.Cell(iRow, iCol).Shape.TextFrame.TextRange.Font.Size = 9
Next iCol
Next iRow
Else 'NO
'Don't change placeholders
If Not oshp.Type = msoPlaceholder Then
If oshp.HasTextFrame Then
oshp.TextFrame.TextRange.Font.Size = 9
End If
End If
End If
Next oshp
Next osld
End Sub

qiyusi
12-09-2014, 01:50 AM
Ok i got it:)

above code works well.

Once again thanks for your help.

i guess case SOLVED.

is there no thanks button in this thread reply?