power point VBA , tables

ziad alsayed

Well-known Member
Joined
Jul 17, 2010
Messages
665
dear all
i have a power presentation with seven slides, each slide has a title and table, i need to select each table in each slide and put its measurments (width and Height), of course the tables dont have the same measurments
hope you can assist me with a code that select each table in each slide and i will add the measurments.
thanks in advance.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hello
I'm not sure if I understood exactly what you want to do, where are the measurements supposed to go?
Anyway, here's some code:

Code:
' this is a PowerPoint macro


Sub TableData()
Dim tb As Table, shp As Shape, tg$, i%


For i = 1 To ActivePresentation.Slides.Count
    tg = ""
    For Each shp In ActivePresentation.Slides(i).Shapes
        If shp.HasTable Then
            tg = shp.Name      ' finds first table
            Exit For
        End If
    Next
    Select Case tg
        Case Is = ""
            
            MsgBox "Slide " & i & " has no tables", vbCritical
            
        Case Else       ' show table info
            
            MsgBox "Width : " & shp.Width & vbNewLine & "Height : " & shp.Height & vbNewLine & _
            "Number of rows : " & shp.Table.Rows.Count & vbNewLine & "Number of columns : " & _
            shp.Table.Columns.Count, vbInformation, "Table at Slide " & i & " = " & tg
            
    End Select
Next
            
End Sub
 
Upvote 0
Dear Worf

thanks for your relpy. this is not what it need.i normaly run my macro from excel to get my power point presentation.now in my power presentation i have seven slides, and each slide has one table ( tables dont have the same number of rows and columns), but all the tables in presentation has the same height and the same width (Width is 710 and height is 476).
for exampe the table in first slide has (Width is 710 and height is 476) but is should be (Width is 595 and height is 375), the second should have different width and height.

so i need a code that will select the first table and make the width 595 and 476 , then select the second table and make the width 400 and height 250 for example and so on.

i hope i am explain well.
note : if possible i can send you file ( before and after ).

thanks in advance.
 
Upvote 0
note : if possible i can send you file ( before and after ).

This forum does not support annexes, but you can upload files to any hosting site and paste the link here.

Concerning your other thread with the merged cells question, I'll answer soon...
 
Upvote 0
Hello
See if this does it.
Now I´ll work on the merged cells thread...

Code:
Option Explicit
Option Base 1
' this code goes at a PowerPoint module
Sub SizeTables()
Dim TabWid, TabHei, shp As Shape, i%
TabWid = Array(400, 300, 200)   ' desired table widths
TabHei = Array(350, 250, 150)   ' desired table heights
If UBound(TabWid) <> UBound(TabHei) Then Exit Sub
For i = 1 To UBound(TabWid)     ' this example works with 3 slides
    For Each shp In ActivePresentation.Slides(i).Shapes
    
        If shp.HasTable Then Exit For   ' finds first table
        
    Next
    shp.Width = TabWid(i)
    shp.Height = TabHei(i)
    
Next
End Sub
 
Upvote 0
Dear Worf

sorry for the delay i was not feeling good .

this is the idea i need , but instead of looping through the slides and select tables, i want to select slide by slide and then the table in the slide and put the parameters.

so if i have 3 slides as per your example i will have to add 3 times the parameters ( of course the parameters ar not the same).

so the code will be something like that
select Slide (1), table, parameters
select slide (2), table, parameters
select slide(3), table, parameters
 
Upvote 0
Hello Ziad
My code already does what you described. I added message boxes, if you run the example it will become clearer.

Code:
Option Explicit
Option Base 1
' this code goes at a PowerPoint module
Sub SizeTables()
Dim TabWid, TabHei, shp As Shape, i%
TabWid = Array(400, 300, 200)   ' desired table widths
TabHei = Array(350, 250, 150)   ' desired table heights
If UBound(TabWid) <> UBound(TabHei) Then Exit Sub
For i = 1 To UBound(TabWid)     ' this example works with 3 slides
    MsgBox "Working with slide #" & i, 64
    For Each shp In ActivePresentation.Slides(i).Shapes
    
        If shp.HasTable Then
            MsgBox "Found table at slide #" & i, 64
            Exit For   ' finds first table
        End If
        
    Next
    shp.Width = TabWid(i)
    shp.Height = TabHei(i)
    MsgBox "Table resized at slide #" & i, vbInformation
    
Next
End Sub
 
Upvote 0
Dear Worf

sorry but this is not what i need.

did you check the link i sent to you?

anyway thanks for your time and effort you put to in solving this issue.


please can you send me a code that will collect the first slide and the first table and make the Width 595 and height is 375.

i willl replicate the code by changing the slide number , table number , height and width.
 
Upvote 0
dear Worf
please ignore my previous email, i just understood the code :):):)
this is working perfectly.

i just need now to center the table in the middle of the slide.


a very big thanks for you :beerchug: .
 
Upvote 0

Forum statistics

Threads
1,225,635
Messages
6,186,128
Members
453,340
Latest member
Stu61

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top