Friday, August 21, 2009

HRESULT E_FAIL PowerPoint Solution

I was looking into developing some Office utilities using their DLLs, and for starters--creating a tool for generating PowerPoint presentations from an image directory using C#.

But when I ran this code:
ApplicationClass powerpoint = new ApplicationClass();
Presentation ppt = powerpoint.Presentations.Add(MsoTriState.msoFalse);
I got this exception:
Error HRESULT E_FAIL has been returned from a call to a COM component
I've been looking for an answer for a while (for at least 10 minutes!) when it was finally time to ask it in a forum.

So thanks to this post I found out that you must install the Visual Basic for Applications from the Microsoft Office CD in order to actually use the DLLs Microsoft supplies:



This solution also applies for developing with other Office products such as Word, Outlook and others.

5 comments:

  1. This sometimes happened when a "not implemented" exeption was thrown as well.

    ReplyDelete
  2. now, end 2012, I was having the exact same issue.
    VS2010 and office 2010 btw.

    I've been pondering for a little more then 10mins, more like a day+, untill I found this post.

    Thank you for actually POSTING your 'solution'.
    Found a lot of threads with similiar issues, with no answer posted...
    So thank you from way in to the future!

    ReplyDelete
  3. Thanks for the tip!

    I found that I also had to install "Microsoft Forms 2.0 .NET Programmability Support" as well. It's located under "Office Tools".

    Hope this tip saves someone time.

    ReplyDelete