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 46
AndyAinscowFreelance programmer / ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
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
Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook 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 GarrochSenior Technical Consultant at BrightCarbonCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.