S
SimD
Hi,
I have a problem creating a new PowerPoint document from the
Microsoft.Office.Interop.PowerPoint PIA. My application crashes here:
ApplicationClass myApp = new ApplicationClass();
Presentation presentation;
=> presentation = myApp.Presentations.Add
(Microsoft.Office.Core.MsoTriState.msoFalse);
with the following exception:
System.Runtime.InteropServices.COMException
Message: Error HRESULT E_FAIL has been returned from a call to a
COM component.
ErrorCode: -2147467259 (0x80004005)
StackTrace: at Microsoft.Office.Interop.PowerPoint.Presentations.Add
(MsoTriState WithWindow) [ ... ]
I've added references to the Microsoft.Office.Interop.PowerPoint and
the Microsoft.Office.Core assemblies at version 11 (Office 2003). I
only have Office 2003 installed on my machine, with the Office 2007
compatibility pack (Office 2007 isn't installed and has never been
neither). If I add the following line after the creation of the
Application instance:
myApp.Activate();
the main window of PowerPoint shows up as expected and I'm then able
to manually create a new presentation from the GUI (File, New...). I
then execute this line in the immediate window:
presentation = myApp.ActivePresentation;
and I'm then able to execute the rest of my program successfully.
This problem only seems to occur with the PowerPoint interop, since
this code (with the Interop.Word assembly) works well:
object missing = System.Reflection.Missing.Value;
object startIndex = 0;
ApplicationClass myApp = new ApplicationClass();
Document wordDocument = myApp.Documents.Add(ref missing, ref missing,
ref missing, ref missing);
Range documentRange = wordDocument.Range(ref startIndex, ref
missing);
documentRange.Font.Name = "Arial";
documentRange.InsertAfter("Test");
object fileName = @"C:\test.doc";
object fileFormat = WdSaveFormat.wdFormatDocument;
object addToRecentFiles = false;
object saveOptions = WdSaveOptions.wdDoNotSaveChanges;
wordDocument.SaveAs(ref fileName, ref fileFormat, ref missing, ref
missing, ref addToRecentFiles, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing);
myApp.Quit(ref saveOptions, ref missing, ref missing);
I've Googled that error quite a bit in the last few days, and still
didn't find any working solution. I've tried almost everything from
that point on, including uninstalling and reinstalling all Office 2007
system files and updates. I'd really appreciate if anyone could help
me on this, before I start looking for alternatives to create
PowerPoint files...
Thanks !
Simon
I have a problem creating a new PowerPoint document from the
Microsoft.Office.Interop.PowerPoint PIA. My application crashes here:
ApplicationClass myApp = new ApplicationClass();
Presentation presentation;
=> presentation = myApp.Presentations.Add
(Microsoft.Office.Core.MsoTriState.msoFalse);
with the following exception:
System.Runtime.InteropServices.COMException
Message: Error HRESULT E_FAIL has been returned from a call to a
COM component.
ErrorCode: -2147467259 (0x80004005)
StackTrace: at Microsoft.Office.Interop.PowerPoint.Presentations.Add
(MsoTriState WithWindow) [ ... ]
I've added references to the Microsoft.Office.Interop.PowerPoint and
the Microsoft.Office.Core assemblies at version 11 (Office 2003). I
only have Office 2003 installed on my machine, with the Office 2007
compatibility pack (Office 2007 isn't installed and has never been
neither). If I add the following line after the creation of the
Application instance:
myApp.Activate();
the main window of PowerPoint shows up as expected and I'm then able
to manually create a new presentation from the GUI (File, New...). I
then execute this line in the immediate window:
presentation = myApp.ActivePresentation;
and I'm then able to execute the rest of my program successfully.
This problem only seems to occur with the PowerPoint interop, since
this code (with the Interop.Word assembly) works well:
object missing = System.Reflection.Missing.Value;
object startIndex = 0;
ApplicationClass myApp = new ApplicationClass();
Document wordDocument = myApp.Documents.Add(ref missing, ref missing,
ref missing, ref missing);
Range documentRange = wordDocument.Range(ref startIndex, ref
missing);
documentRange.Font.Name = "Arial";
documentRange.InsertAfter("Test");
object fileName = @"C:\test.doc";
object fileFormat = WdSaveFormat.wdFormatDocument;
object addToRecentFiles = false;
object saveOptions = WdSaveOptions.wdDoNotSaveChanges;
wordDocument.SaveAs(ref fileName, ref fileFormat, ref missing, ref
missing, ref addToRecentFiles, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing, ref missing, ref missing);
myApp.Quit(ref saveOptions, ref missing, ref missing);
I've Googled that error quite a bit in the last few days, and still
didn't find any working solution. I've tried almost everything from
that point on, including uninstalling and reinstalling all Office 2007
system files and updates. I'd really appreciate if anyone could help
me on this, before I start looking for alternatives to create
PowerPoint files...
Thanks !
Simon