Automating powerpoint - how to determine if it is busy?

I'm automating a powerpoint presentation from a Microsoft Access database.
On my development PC it works perfectly.
In the real environment (with brand new PC's) it will sometimes work and at other times fail with odd error messages but at different locations in the code with the same data.

Turning anti virus off makes no difference.

I've stuck some code in to slow Access down and that seems to cure it or at least temporarily cure it.

To me it looks like powerpoint is not always able to complete an action before Access is giving it the next task.  A timing problem.


    Set objPwrPnt = CreateObject("Powerpoint.application")

So is there a way to determine if objPwrPnt is busy (or idle) ?
LVL 45
AndyAinscowFreelance programmer / ConsultantAsked:
Who is Participating?
 
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
There is no API for idle/busy so you would need to check that what you have asked PowerPoint to create has been completed before issuing the next task.
0
 
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
Once the PowerPoint object has been created, you are presumably creating a Presentation object.

Perhaps you could therefore test to see if it exists like this:

Dim oPres as Object ' Late binding
Do While objPwrPnt.Presentations.Count = 0
  Set oPres = objPwrPnt.Presentations.Add (msoFalse) ' Without a window, change to msoTrue to see the window
  DoEvents
Loop

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantAuthor Commented:
Thanks, but that isn't what I asked for.
For example it might fail when filling in a dataset of a chart - having just filled in 30 charts without problem.  On rerunning it might fail on the third chart with the same data.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
AndyAinscowFreelance programmer / ConsultantAuthor Commented:
Unfortunately it isn't necessarily a 'create' that is failing, it might be filling a dataset or some other task.
0
 
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
If you are asking application B to perform a task from application A and you're seeing suspected timing issues, I would design your code to check that what you're asking the app B object to do has been done before you progress to the next task in app A. I can't see another way round this type of issue. I've come across this type of timing issue when using the clipboard within PowerPoint and checking that the object exists within a Do While...Loop after executing the paste command was the only way to make the code run reliably across a multitude of platform combinations.

Alternatively, stick with your forced delay using something like this:

Option Explicit

#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

Sub Test()
  Debug.Print "Start sleep at " & Now
  Sleep 1000
  Debug.Print "Wake up at " & Now
End Sub

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantAuthor Commented:
>>I would design your code to check that what you're asking the app B object to do has been done before you progress to the next task in app A

Erm, isn't that what I said I wanted to do in the question.  Anyway I've just finished some code with a variety of Windows API calls to hopefully accomplish that.


Forced delay.  Considered that, bit of a crude hack - make things take rather longer to finish and still might fail.
0
 
AndyAinscowFreelance programmer / ConsultantAuthor Commented:
Pity - Microsoft could do with having that.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.