Question

Okay so I've managed to write the following code so far but i keep getting a 424 object required error on the line beginning with range. Can anyone tell me how to fix this?

Sub GetText()     
    Set PPApp = GetObject(, "PowerPoint.Application")  
    i = 1
    Do While i <= PPApp.ActivePresentation.Slides(1).Shapes.Count
       If PPApp.ActivePresentation.Slides(1).Shapes(i).Type = msoTextBox Then
          range(Cells(i, 15)).Value = PApp.ActivePresentation.Slides(1).Shapes(i).TextFrame.TextRange.Text
       End If
       i = i + 1
    Loop 
End Sub
Was it helpful?

Solution

You have two errors in your code.

  1. Simoco has already addressed your first error. i.e you need to use Cells(i, 15).Value instead of range(Cells(i, 15)).Value

  2. You have a typo. If you would have used Option Explicit then you would have known where the error is ;)

You have PPApp as the powerpoint object but are using PApp and hence the object required error

Also please declare your variables and fully qualify your objects.

Is this what you are trying?

Option Explicit

Sub GetText()
    Dim PPApp As Object
    Dim ws As Worksheet
    Dim i As Long

    Set PPApp = GetObject(, "PowerPoint.Application")

    i = 1

    '~~> Change this to the relevant sheet
    Set ws = ThisWorkbook.Sheets("Sheet1")

    Do While i <= PPApp.ActivePresentation.Slides(1).Shapes.Count
       If PPApp.ActivePresentation.Slides(1).Shapes(i).Type = msoTextBox Then
          ws.Cells(i, 15).Value = PPApp.ActivePresentation.Slides(1).Shapes(i).TextFrame.TextRange.Text
       End If
       i = i + 1
    Loop
End Sub

Few Other observations.

  1. You are using GetObject. If there are multiple instances of powerpoint then you many not get the correct result.

  2. You are incrementing the value of i even when the shape is not msoTextBox. This may result in you skipping the rows while writing to the Excel Sheet. You may want to use a different variable and increment that inside the If-EndiF

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top