-3

I am just trying to make an empty slide object by doing this -

Microsoft.Office.Interop.PowerPoint.Slide empty_slide = new Microsoft.Office.Interop.PowerPoint.Slide();

The error is:

Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the
 COM class factory for component with CLSID {91493445-5A91-11CF-8700-00AA0060263
B} failed due to the following error: 80040154 Class not registered (Exception f
rom HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOn
ly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Bo
olean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipChec
kThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean s
kipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Program.GetBulletPointTransition(Application PowerPoint_App, Presentation
presentation) in c:\Users\PEAK\Documents\Peak Sourcing\Work\ppt_test\ppt_test\Pr
ogram.cs:line 539
   at Program.Main(String[] args) in c:\Users\PEAK\Documents\Peak Sourcing\Work\
ppt_test\ppt_test\Program.cs:line 79
Press any key to continue . . .

I would appreciate some help.

user1394252
  • 41
  • 2
  • 11

2 Answers2

1

HERE'S THE CORRECT ANSWER:

You should not directly create new instances of class Microsoft.Office.Interop.PowerPoint.Slide. Instead, use code like the following:

        Presentation ppt = pptApp.Presentations.Open(pptPath, WithWindow: MsoTriState.msoFalse);
        int newSlideNumber = (ppt.Slides.Count + 1);
        var slide = ppt.Slides.Add(newSlideNumber, PpSlideLayout.ppLayoutTitleOnly);
        slide.Shapes[1].TextFrame.TextRange.Text = "hello!";

NOTE: In case you checked the relevant forums for available answers to your question, you should NOT change the project's build settings to use platform target of x86.

Ofer
  • 423
  • 6
  • 11
0

Just remove the empty_slide = null; part from your first code. That should do it. Use the following -

Microsoft.Office.Interop.PowerPoint.Slide empty_slide = new Microsoft.Office.Interop.PowerPoint.Slide();
NBM21
  • 47
  • 1
  • 8