PowerPoint automation "Run-time error '0'"

R

RAHUL

Hi All,

While doing PowerPoint automation in my VC++ code the function
"InsertFromFile" fails and a "Run-time error '0'" dialog comes. Could
somebody please tell what might be causing this error. Since there is
no error code (its 0) I do not know how to proceed.

Since an error dialog is shown by PowerPoint saying "Run-time error
'0'" all of the automation statements after the call "InsertFromFile"
fails because PowerPoint do not responds and the functions (e.g. Save
()) times out and throws exception.

Is there any way to dismiss the dialog "Run-time error '0'"
automatically so that the latter statements succeeds.

The same "Run-time error '0'" comes when I try to do the same thing in
VBA script (as mentioned in the code below). But surprisingly the
error does not come it I open the presentation with a window and make
PwoerPoint visible.

Thanks
Rahul

VBA equivalant of my VC++ source code (This also causes error)

Sub Macro1()

Set App = CreateObject("PowerPoint.Application")

Set presSet = App.Presentations
Set finalPres = presSet.Open("C:\Work\Bugs\test.ppt",
MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse)

Set dstSlides = finalPres.Slides
dstSlides.InsertFromFile "C:\Work\Bugs\test.1.ppt", 2
finalPres.Save
End Sub
 
S

Steve Rindsberg

Hi Rahul. There are some things in PPT that, I swear, are simply not
destined ever to make sense. There may be a better way around this but
what's worked for me is to add one dummy slide to the new presentation,
insert slides from another file after it, then delete the first slide if
you like.

Sub ThisWorks()

Dim oPres As Presentation

' Add a new presentation invisibly
Set oPres = Presentations.Add(False)

' ADD A DUMMY SLIDE TO THE PRESENTATION
oPres.Slides.Add 1, ppLayoutBlank

' Insert your new slides after the dummy slide
oPres.Slides.InsertFromFile "c:\temp\killme.ppt", 1

' Delete the dummy slide
oPres.Slides(1).Delete

' The rest is just for test purposes ...
' Save the presentation, close it, reopen it with window
' so you can see if it worked:
oPres.SaveAs "C:\temp\test.ppt"
oPres.Close
Presentations.Open "c:\temp\test.ppt"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top