Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class not registered VBA excel

I'm trying to copy slides from one PowerPoint presentation to another with the use of a VBA script in excel. Found the below code but when trying to run it I get the following error:

enter image description here

I'm working on 64 bit machine and I'm using the following references:

  • Visual Basic For Applications
  • Microsoft Excel 16.0 object library
  • OLE Automation
  • Microsoft Office 16.0 object library
  • Microsoft PowerPoint 16.0 object library
Sub Example2()

    Dim objPresentation As Presentation
    Dim i As Integer
    
    'open the target presentation
    Set objPresentation = Presentations.Open("C:\Users\john\Desktop\123.pptx")
    For i = 1 To objPresentation.Slides.Count
        objPresentation.Slides.Item(i).Copy
        Presentations.Item(1).Slides.Paste
        Presentations.Item(1).Slides.Item(Presentations.Item(1).Slides.Count).Design = _
            objPresentation.Slides.Item(i).Design
    Next i
    objPresentation.Close

End Sub

Could someone please help me overcome this error?

like image 604
Lobo1908 Avatar asked Apr 27 '26 00:04

Lobo1908


1 Answers

You have not declared a Powerpoint application object.

Dim objPowerPoint As New PowerPoint.Application
Dim objPresentation As Presentation
Dim i As Integer

'open the target presentation
Set objPresentation = objPowerPoint.Presentations.Open("C:\Users\john\Desktop\123.pptx")

'~~> Rest of the code
like image 69
Siddharth Rout Avatar answered Apr 28 '26 19:04

Siddharth Rout