Search code examples
arraysvbaselectpowerpointinputbox

Inputbox to select slides in Powrpoint presentation. (Almost done)


Hello all smart peeps out there,

I want to select some Powerpointslides based on inputs from the inputbox and I can't get it to work. It's probably something wrong with the how I declare variables. I have created a macro which names Powerpointslides and I want to select the name of the slides with the inputbox with the help of VBA.

So basically I want the inputbox to return an Array of slide names. Let's say: I want to select a sheet called USA and Sweden if I enter it in the input box. This is what I have tried so far.

Sub Select_Slides()


slides = InputBox("Insert Slide names to select")

list = Array(slides)

ActivePresentation.Slides.Range(list).Select

End Sub

In order for it to work list has do be be an Array of a sheet called USA and Sweden. I have a macro which creates a new Powerpoint with only selected slides. So this is why I want to select slides via the input box.

Thanks


Solution

  • Just a reminder: The Split method can do most of the heavy lifting when you need to convert a delimited string to an array.

    Sub SplitExample()
    
        Dim sText As String
        ' This would be your InputBox results, but for demo purposes:
        Dim aInputarray() As String
        Dim x As Long
    
        sText = "USA,Sweden"
    
        ' Split takes the text to split and the delimiter as parameters
        ' and returns a 0-based array
        aInputarray = Split(sText, ",")
    
        For x = LBound(aInputarray) To UBound(aInputarray)
            Debug.Print aInputarray(x)
        Next
    
    End Sub