Koba
Koba

Reputation: 15

424 Error while using Macro on TextBox1 even tho exists

I'm fairly new to VBA and I have looked onto other forums and etc. I always get the error 424 Object required when I click on the confirm button (The confirm button has the macro SlimKeyCheck) The TextBox1 is located on Slide10.

The Macro SlimKeyCheck looks like this:

Sub SlimKeyCheck()
If Slide10.TextBox1.Text = "Hey" Then
    MsgBox ("Nah")
End If
End Sub

Any help would be thankful!

Upvotes: 0

Views: 71

Answers (1)

ClintK
ClintK

Reputation: 74

Since you are new to VBA it would be a good idea to familiarize yourself with the Object Model used by Powerpoint (as well as all Office products). I would recommend having a look here. It is built on a kind of hierarchy of objects. Presentation > Slide > Shapes (Testbox is a type of shape).

Just because the slide is slide 10 does not mean its name is such.

You can use this code to determine the index, ID, and name of the slides in your presentation.

Public Sub Slide_Stats()
    Dim slide As slide
    For Each slide In ActivePresentation.Slides
        Debug.Print slide.SlideIndex, slide.SlideID, slide.Name,  
    Next slide
End Sub

The information will be displayed in columns in the immediate window of the vba editor (Ctrl + G).

A given slide then can be accessed by:

ActivePresentation.Slides(index)

ActivePresentation.Slides("Slide1")

or

ActivePresentation.Slides.FindBySlideID(ID)

where index, "Slide1" and ID are those obtained from the above code.

Similarly you can determine the textboxes' name and id of a given slide like this:

Public Sub Textbox_stats()
    Dim box As Shape
    For Each box In ActiveWindow.View.slide.Shapes
        If box.type = 17 Then
            Debug.Print box.Id, box.Name
        End If
    Next box
End Sub

Since a textbox is part of the Shapes collection of objects, you have to specify you want type 17 (textbox) only. This page describes the types of shapes in the collection.

In summary, BigBen gave a simple example of how to access the text of a known Textbox object. Here is another:

ActivePresentation.Slides("Slide1").Shapes("TextBox 3").TextFrame2.TextRange.Text

using the slide name ("Slide1") and shape name ("TextBox 3").

I think I may have went overboard with the details. Ask any questions you may have.

Upvotes: 3

Related Questions