Inputbox to prompt the user to enter a slide number

Dear Experts:

below macro...
... retrieves several pieces of information from a table on the first slide,
... puts this alltogether into a text box
... which in turn is placed on the bottom of the slides starting from page 2.

I now would like to get this macro tweaked as follows:

The table from which the information is retrieved could be on page 2 or 3 or even on subsequent page.

I therefore would like to get the macro tweaked on line 18 and 26 of the current code:

An inputbox (only numeric integer values are allowed, no greater than the overall number of slides minus 1) is to prompt the user to specify the page number of the table from which to take the data (line 18)

Line 26 should then be adjusted accordingly.

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

Sub IPS()
Dim pre As Presentation
Dim shp As Shape
Dim strText As String
Dim i As Long
Dim tbl As Variant
Dim shp1 As Variant
Dim tb As Variant



    Set pre = ActivePresentation

If MsgBox("Would you like to insert the metadata into the footer of the current presentation?", vbQuestion + vbYesNo, "Add Footer") = vbNo Then
Exit Sub
End If


    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, 566, 750, 40) 'Left, Top, Width, Height
            tb.TextFrame.TextRange.Text = strText
            tb.AlternativeText = "TableText"
            tb.TextFrame2.TextRange.Font.Name = "Calibri Light"
            tb.TextFrame2.TextRange.Font.Size = 13
        Next i
    End With
    
End Sub

Open in new window

Andreas HermleTeam leaderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JSRWilsonCommented:
Maybe something based on

Sub IPS()
Dim pre As Presentation
Dim shp As Shape
Dim strText As String
Dim i As Long
Dim tbl As Variant
Dim shp1 As Variant
Dim tb As Variant
Dim lngIndex As String


    Set pre = ActivePresentation

If MsgBox("Would you like to insert the metadata into the footer of the current presentation?", vbQuestion + vbYesNo, "Add Footer") = vbNo Then
Exit Sub
End If
'''''''''''''''Input Box
Do
Do
lngIndex = InputBox("Enter slide number with table")
Loop While Not IsNumeric(lngIndex)
Loop While lngIndex > pre.Slides.Count - 1 Or lngIndex = 0

''''''''''''''''''''''''
    With pre
        For Each shp In .Slides(lngIndex).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, 566, 750, 40) 'Left, Top, Width, Height
            tb.TextFrame.TextRange.Text = strText
            tb.AlternativeText = "TableText"
            tb.TextFrame2.TextRange.Font.Name = "Calibri Light"
            tb.TextFrame2.TextRange.Font.Size = 13
        Next i
    End With
    
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Hi JSR,

thank you very much for your swift help.

I am afraid to tell you that your code throws an error message on line 26. I got no idea why because your code looks perfect to me.

The error message is as follows and comes up regardless of which slide number I enter into the input box. Very Strange ...

error_message_on_inputBox
Help is very much appreciated. Thank you very much in advance. Regards, Andreas
0
Andreas HermleTeam leaderAuthor Commented:
Hi JSR, found out myself how to cope with this error message ... will post the respective code tomorrow ...
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

JSRWilsonCommented:
Hopefully you converted the string to a Long

Do
Do
lngIndex = InputBox("Enter slide number with table")
Loop While Not IsNumeric(lngIndex)
i = CLng(lngIndex)
Loop While i > pre.Slides.Count - 1 Or i = 0

''''''''''''''''''''''''
    With pre
        For Each shp In .Slides(i).Shapes
End Sub
0
Andreas HermleTeam leaderAuthor Commented:
uppps, sorry, inadvertently pressed the wrong button.
0
Andreas HermleTeam leaderAuthor Commented:
There is something wrong with this website. I cannot award points, I just do not see the respective buttons for it.
0
Andreas HermleTeam leaderAuthor Commented:
Has JSR been awarded the 1000 points? I got no idea.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.