Pages

Monday, November 21, 2011

Find table names in PowerPoint using VBA

If you want to know the names of all the tables in PowerPoint slide. So that  we can easily refer to any of the table. Try this macro-


Sub find_table_names()
' tools -> refrence select -> Microsoft powerpoint

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim oPS As PowerPoint.Slide

Dim Shp As Object
Dim i As Integer, j As Integer

Set PPApp = New PowerPoint.Application
PPApp.Visible = True
    ' open the sample ppt in which u have already made tables ,etc.
    Set PPPres = PPApp.Presentations.Open("C:\Documents and Settings\user\Desktop\New Blog Look\Excel to ppt\Sample_template_V1.potx")
    For Each oPS In PPPres.Slides
        For Each Shp In oPS.Shapes
        ' check if the shape is table or not
            If Shp.HasTable Then ' get table name, cell no and row no
                For i = 1 To Shp.Table.Rows.Count
                    For j = 1 To Shp.Table.Columns.Count
                    Shp.Table.Cell(i, j).Shape.TextFrame.TextRange.Text = "Table Name: " & Shp.Name & vbCrLf & "Row No: " & i & vbCrLf & "Col No: " & j
                    Next
                Next
            End If
        Next
    Next
End Sub

No comments:

Post a Comment