Excel VBA Run-time error -2147221164 (80040154) Class not registered

Nina 1 Reputation point
2021-01-26T14:04:19.387+00:00

Hello and Thank you in advance for your assistance!

I am somewhat new to VBA and I am running into an error that I have never seen before. I tested on 2 computers (personal and company) and get the error on both.

I am trying to get the position of a picture in powerpoint using an excel vba code using the immediate window and I get the error Run-time error -2147221164 (80040154) Class not registered

References to powerpoint and of course Microsoft excel are set up. (see below, not sure if pic will show).
60516-image.png

Here's the code

sub picsize()

Dim SD As Slide

Dim SH As Shape

Set shp = ActivePresentation.Slides(1).Shapes(1)

Debug.Print shp.Top
Debug.Print shp.Left
Debug.Print shp.Width
Debug.Print shp.Height

End Sub

Any assistance is appreciated!

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. HansV 966 Reputation points MVP
    2021-01-26T15:05:22.957+00:00

    You declare a variable SH but use shp instead.
    If you are running this code from Excel, it is not clear what ActivePresentation refers to.
    Is PowerPoint supposed to be open when you run the macro? If so, it should look like this:

    Sub picsize()
        Dim PP As PowerPoint.Application
        Dim PR As PowerPoint.Presentation
        Dim SD As PowerPoint.Slide
        Dim SH As PowerPoint.Shape
    
        On Error Resume Next
    
        Set PP = GetObject(Class:="PowerPoint.Application")
        If PP Is Nothing Then
            MsgBox "PowerPoint is not running!", vbExclamation
            Exit Sub
        End If
    
        Set PR = PP.ActivePresentation
        If PR Is Nothing Then
            MsgBox "There is no active presentation in PowerPoint!", vbExclamation
            Exit Sub
        End If
    
        Set SD = PR.Slides(1)
        If SD Is Nothing Then
            MsgBox "The active presentation doesn't contain any slides!", vbExclamation
            Exit Sub
        End If
    
        Set SH = SD.Shapes(1)
        If SH Is Nothing Then
            MsgBox "The first slide doesn't contain any shapes!", vbExclamation
            Exit Sub
        End If
    
        Debug.Print SH.Top
        Debug.Print SH.Left
        Debug.Print SH.Width
        Debug.Print SH.Height
    End Sub
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.