write ppt textboxes to excel.

bbrimberry

New Member
Joined
Mar 23, 2016
Messages
34
hello all,

I am trying to loop through all ppt textboxes in the active pres and write the data to excel

here's the code.. currently it's throwing a class not registered error.
would appreciate any help.

thanks!




Dim ppapp As PowerPoint.Application

Dim pppres As PowerPoint.Presentation



Sub getshapedata()

'On Error GoTo line1

Set ppapp = GetObject(, "Powerpoint.application")

Set pppres = ppapp.ActivePresentation



Dim shapeslide

Dim shapename

Dim shapetext

Dim nextrow

Dim currentSlide As Slide

Dim shp As Shape







For Each currentSlide In ActivePresentation.Slides



For Each shp In currentSlide.Shapes

' Check if the shape type is msoTextBox

If shp.Type = 17 Then



shapeslide = currentSlide.SlideIndex

shapename = shp.Name

shapetext = shp.TextEffect





nextrow = Sheet1.Range("a" & Rows.Count).End(xlUp).Row + 1



Sheet1.Range("a" & nextrow) = shapeslide

Sheet1.Range("b" & nextrow) = shapename

Sheet1.Range("c" & nextrow) = shapetext







End If

Next shp

Next currentSlide





End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi bbrimberry,

first of all, you should be aware by now that you need to post code between cod brackets. Simple to do and you will get a better response to your questions, because it makes it much easier to read your question. Click on the little VBA icon above the post area and paste your code.

I am assuming you have added the Microsoft Powerpoint reference to your project, else you will get errors during the compile.
If not (or for other readers), go to Tools menu, References..., then go down the list until Microsoft Powerpoint Object Library and put a tick in front.

Now the VBA editor will find all the required references to PowerPoint objects

Also you are a bit sloppy with your coding, Dim'ming everything as variants, using names that are look-alike, not using some capitalisation in the names. This will cause you lots of headaches in the end.

Dim'ming something as a Shape in Excel VBA will lead to an error if it refers to a PowerPoint shape, so you need to define it as Powerpoint.Shape.

VBA Code:
Option Explicit



Sub GetShapeData()

    Dim ppApp As PowerPoint.Application
    Dim ppPres As PowerPoint.Presentation
    Dim iSlideNum As Integer
    Dim sName As String, sText As String
    Dim lNextRow As Long
    Dim currentSlide As PowerPoint.Slide
    Dim shpS As PowerPoint.Shape
    

    Set ppApp = GetObject(, "Powerpoint.application")
    
    Set ppPres = ppApp.ActivePresentation
    
    
    lNextRow = Sheet1.Range("a" & Rows.Count).End(xlUp).Row
    If lNextRow > 1 Then lNextRow = lNextRow + 1
    
    
    For Each currentSlide In ppPres.Slides
        For Each shpS In currentSlide.Shapes
        
            ' Check if the shape type is msoTextBox  (17)
            
            If shpS.Type = msoTextBox Then
                iSlideNum = currentSlide.SlideIndex
                
                sName = shpS.Name
                
                sText = shpS.TextEffect.Text
                Sheet1.Range("a" & lNextRow) = iSlideNum
                
                Sheet1.Range("b" & lNextRow) = sName
                
                Sheet1.Range("c" & lNextRow) = sText
                lNextRow = lNextRow + 1
            End If
        Next shpS
    Next currentSlide

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top