question

Nina-6602 avatar image
0 Votes"
Nina-6602 asked HansV-7609 answered

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

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!


office-vba-dev
image.png (82 B)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

HansV-7609 avatar image
0 Votes"
HansV-7609 answered

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.