Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

VBA: runtime error '424' Object required when searching for Shape

$
0
0

I created a VBA script to transfer data from Excel to PowerPoint (both Version 2016) and want to check if there exists a specific Shape on Slide x and then copy it to Slide y.

The common solution which is also mentioned in (Existence of shapes in Powerpoint) does produce

"runtime error '424': Object required"

in line 3 of the function at For Each oSh in myPresentation.Slides(4).Shape

Function ShapeExists(ByVal ShapeName as String) as Boolean

Dim oSh as Shape

For Each oSh in myPresentation.Slides(4).Shapes
     If oSh.Name = ShapeName Then
        ShapeExists = True
        Exit Function
     End If
Next
End Function

The code where "ShapeExists" is called:

Set PowerPointApp = GetObject(class:="PowerPoint.Application")
Set myPresentation = PowerPointApp.Presentations.Add

 If ShapeExists("MSDreieck2") Then
    myPresentation.Slides(4).Shapes("MSDreieck2").Copy
    mySlide5.Shapes.PasteSpecial DataType:=0
 Else
    GoTo NACHZEITSTRAHLCOPY:
 End If

I already added the Object Library for Powerpoint 2016 under references and several others. When typing dim oSh as Shape it suggests two different "Shape" items in the list (one for Excel, one for PP) but it doesn't make a difference for the error which one I use.

As far as I'm concerned there is no other way to check if a specific Shape exists as the Shape index gets newly assigned at every run and as the number of Shapes on Slide x is not always the same in my case.

I would be very grateful for every suggestion. Thanks


Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>