(Solved) – VBA object required error despite successful operation

(solved)-–-vba-object-required-error-despite-successful-operation

I want to write a macro for powerpoint that can build many different slides made up of elements from a set of 12 (I called them ‘stencils’) – for each slide only the elements’ order and the text within in the elements changes.

Goal:
Go through lines in excel. Each line represents one usage of a ‘stencil’. In column 5 it says what ‘stencil’ to use (from an ID) and then the other columns contain the texts for the fields.
All the stencils are on the last slide of the presentation from where I copy the relevant one, paste it and fill it with text.

One of those stencils unfortunately is just a textbox nothing more (a headline). All the others are groups of shapes.

When I try to run this code it tells me 424 “Object required” for that line

 .TextFrame.TextRange.Text = wks.Range(line, CLMN).Text

…but after it ran successfully: the header is on the slide and the text is correct.

Can anybody help me out? What is going on? How can it require an object after the fact?

Full Sub:

Sub AddShape(typ As Integer, state As Integer, currentSld As Slide, height As Long, line As Integer)

    'Set the constants (although not implemented as Const)
    Dim CLMN As Integer
    CLMN = 5
    Dim stencils As Shapes
    Dim stencilSlide As Integer
    stencilSlide = CInt(ActivePresentation.Slides.Count)
    Set stencils = ActivePresentation.Slides(stencilSlide).Shapes

    Dim HEADER As Shape
    Set HEADER = stencils("header")

    Dim ALPHANUMERICAL As Shape
    Set ALPHANUMERICAL = stencils("alphanumerical")

    Dim BIRTHDATE As Shape
    Set BIRTHDATE = stencils("birthdate")

    Dim TOGGLE As Shape
    Set TOGGLE = stencils("toggle")

    Dim DROPDOWN As Shape
    Set DROPDOWN = stencils("dropdown")

    Dim NUMERICAL As Shape
    Set NUMERICAL = stencils("numerical")

    Select Case typ
    Case 1
        ALPHANUMERICAL.Copy
    Case 2
        NUMERICAL.Copy
    Case 4
        DROPDOWN.Copy
    Case 5
        TOGGLE.Copy
    Case 9
        BIRTHDATE.Copy
    End Select

    If typ = 10 Then
        HEADER.Copy
        With currentSld.Shapes.Paste
            .Top = height
            .TextFrame.TextRange.Text = wks.Range(line, CLMN).Text
        End With
    Else
        With currentSld.Shapes.Paste
                .Top = height
                    For x = 1 To .GroupItems.Count
                        If .GroupItems(x).Name = "label" Then
                            With .GroupItems(x)
                                .TextFrame.TextRange.Text = wks.Range(line, CLMN).Text
                            End With
                        Else
                            With .GroupItems(x)
                                .TextFrame.TextRange.Text = wks.Range(line, CLMN   CInt(.GroupItems(x).Name)).Text
                            End With
                        End If

                    Next
        End With
    End If


End Sub

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *