running multiple instances of script sometimes fails

  • Thread starter Thread starter Trigger
  • Start date Start date
T

Trigger

I'm getting some strange behaviour while running multiple instances of
the same VBscript. Basically the script merges Powerpoint
Presentations, and works fine alone. However my project requires
several instances of it to run at once - and oddly sometimes it works,
but the other half of the time I'm getting:

Presentation.SaveAs: Object does not exist.
or:
Presentation.Close: Object does not exist.
and other times:
Presentations.Item: Integer out of range. 1 is not in Index's valid
range of 1 to 0

These errors seem random. Could anyone offer me some suggestions?
 
Keep in mind that PowerPoint is a single instance application. Even though
you are running multiple scripts they are "communicating" with this single
instance of PowerPoint. So all references to presentations need to be
unique. For example: If two scripts try to create presentation1 that would
be a problem. Might be something along this line.
 
What Mike said plus ...

You may be running into difficulties with the scope of the variables being
declared. A global variable declared twice will confuse VBA. Try instead
to declare procedure level variables.

B
 
Thanx, that was indeed the problem. Though how would I be able to
reference a unique newly created presentation? Perhaps something like
this?:

Set presentationNum = PPTobj.Presentations.Add(True)
PPTobj.Presentations(presentationNum).Slides.InsertFromFile
"somefilename", 0

Then how would I go about saving this presentation? Right now I have:

PPTobj.ActivePresentation.SaveAs("c:\test\" & newFile)

- but this would seem to only save the current active presentation
(which is mostly likely being assembled by another instance of the
same script).

Any thoughts on this would be very welcome!
 
Trigger said:
Thanx, that was indeed the problem. Though how would I be able to
reference a unique newly created presentation? Perhaps something like
this?:

Set presentationNum = PPTobj.Presentations.Add(True)
PPTobj.Presentations(presentationNum).Slides.InsertFromFile
"somefilename", 0

How about something like:

Dim oPres as Presentation
Set oPres = PPTobj.Presentations.Add(True)
oPres.Slides.InsertFromFile 'etc,etc, etc
oPres.SaveAs("c:\test\" & newFile)
 
Back
Top