Inputbox to prompt the user to enter a slide number

Andreas Hermle
Andreas Hermle used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
CEO PowerPoint Alchemy
Commented:
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

Andreas HermleTeam leader

Author

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
Andreas HermleTeam leader

Author

Commented:
Hi JSR, found out myself how to cope with this error message ... will post the respective code tomorrow ...
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

John WilsonCEO PowerPoint Alchemy

Commented:
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
Andreas HermleTeam leader

Author

Commented:
uppps, sorry, inadvertently pressed the wrong button.
Andreas HermleTeam leader

Author

Commented:
There is something wrong with this website. I cannot award points, I just do not see the respective buttons for it.
Andreas HermleTeam leader

Author

Commented:
Has JSR been awarded the 1000 points? I got no idea.

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