Add text box to the bottom of every slide, the text of the text box to be populated from entries in a table

Andreas Hermle
Andreas Hermle used Ask the Experts™
on
Dear Experts:

I would like to run a macro that performs the following actions:

The macro is to add a text box at the bottom of each and every slide based on entries on a table that is located on the very first slide.

The 2 column, 12 rows table on Slide 1 has the following entries which should be put into that text box.

Row 2, Column 2:   Text 1
Row 9, Column 2:   Text 2
Row 12, Column 2: Text 3

Hence the text box to be added to all the slides (measurments and position: 'msoTextOrientationHorizontal, 30, 560, 750, 40') should look like this on every slide:

Text 1, Text 2, Text 3

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NorieAnalyst Assistant

Commented:
Perhaps.
Dim pre As Presentation
Dim shp As Shape
Dim strText As String
Dim I As Long

    Set pre = ActivePresentation

    With pre
        With .Slides(1).Shapes(1).Table
            strText = .Cell(2, 2).Shape.TextFrame.TextRange.Text & .Cell(9, 2).Shape.TextFrame.TextRange.Text & .Cell(12, 2).Shape.TextFrame.TextRange.Text
        End With
        For I = 2 To .Slides.Count
            pre.Slides(I).Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 560, 750, 40).TextFrame.TextRange.Text = strText
        Next I
    End With

Open in new window

Andreas HermleTeam leader

Author

Commented:
Oh Norie, that was quick. Thank you, will test it as soon as possible :-)
Top Expert 2016

Commented:
You probably watnt comma to separate the 3 texts

Dim pre As Presentation
Dim shp As Shape
Dim strText As String
Dim I As Long

    Set pre = ActivePresentation

    With pre
        With .Slides(1).Shapes(1).Table
            strText = .Cell(2, 2).Shape.TextFrame.TextRange.Text & ", " & _
                .Cell(9, 2).Shape.TextFrame.TextRange.Text & ", " & _
                .Cell(12, 2).Shape.TextFrame.TextRange.Text
        End With
        For I = 2 To .Slides.Count
            pre.Slides(I).Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 560, 750, 40).TextFrame.TextRange.Text = strText
        Next I
    End With

Open in new window

Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Top Expert 2016

Commented:
if the table is not the first shape
then try
Sub Macro()
Dim pre As Presentation
Dim shp As Shape
Dim strText As String
Dim I As Long

    Set pre = ActivePresentation

    With pre
        For Each shp In .Slides(1).Shapes
            If shp.Type = msoTable Then Set tbl = shp.Table
        Next
        With tbl
            strText = .Cell(2, 2).Shape.TextFrame.TextRange.Text & ", " & _
                .Cell(9, 2).Shape.TextFrame.TextRange.Text & ", " & _
                .Cell(12, 2).Shape.TextFrame.TextRange.Text
        End With
        For I = 2 To .Slides.Count
            pre.Slides(I).Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 560, 750, 40).TextFrame.TextRange.Text = strText
        Next I
    End With

End Sub

Open in new window

Andreas HermleTeam leader

Author

Commented:
Hi Norie, hi Rafael

I am afraid to tell you that your code throws an error message (runtime error 8000 4005) on line 9

So does Rafael's first trial at this job (line 10)

Rafael your second code however does the trick . Thank you very much for it.

There is one thing I would like to have incorporated as well. Renewed running of the macro should delete all these textboxes at the bottom (I guess they need to be named programmatically) and then re-inserted with the current metadata.

I guess this is feasible.

Thank you very much for your great help. Regards, Andreas
Top Expert 2016
Commented:
then try
Sub Macro1()
Dim pre As Presentation
Dim shp As Shape
Dim strText As String
Dim I As Long

    Set pre = ActivePresentation

    With pre
        For Each shp In .Slides(1).Shapes
            If shp.Type = msoTable Then Set tbl = shp.Table
        Next
        With tbl
            strText = .Cell(2, 2).Shape.TextFrame.TextRange.Text & ", " & _
                .Cell(9, 2).Shape.TextFrame.TextRange.Text & ", " & _
                .Cell(12, 2).Shape.TextFrame.TextRange.Text
        End With
        For I = 2 To .Slides.Count
            For Each shp1 In pre.Slides(I).Shapes
                If shp1.AlternativeText = "TableText" Then shp1.Delete
            Next
            Set tb = pre.Slides(I).Shapes.AddTextbox(msoTextOrientationHorizontal, 30, 560, 750, 40)
            tb.TextFrame.TextRange.Text = strText
            tb.AlternativeText = "TableText"
        Next I
    End With

End Sub

Open in new window

Andreas HermleTeam leader

Author

Commented:
Great job, Rafael, as always, very nice coding. Works like a charm.

Regards, Andreas

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial