Problem automating Powerpoint with Excel VBA

L

leef_me

I am not well versed in automation across applications. Can anyone help
me by testing, correcting my error, or confirming a PPT bug?

I have a working Excel macro that opens a Powerpoint file with song
lyrics, via automation. I have tried it under Win XP, PPT 2000 and
Execl 2000, without failure. In one set of conditions under Win XP, PPT
2002 and Execl 2002, I have an undesired condition: Powerpoint does not
move to the foreground.
Conditions to recreate the failure are as follows:
1) Under Win XP, PPT 2002 and Execl 2002
2) both application closed
3) open the Excel workbook with the macro, with macros enabled
4) use the macro to open the desired PPT file with lyrics
5) PPT comes to the foreground with the file visible
6) manually close the PPT file, leaving PPT application open
7) use the macro to open the desired PPT file with lyrics
8) the PPT file is opened, but PPT stays in the background, BAD
9) repeating steps 6 through 8 will give the same BAD result
10) closing PPT applicaton and repeating steps 4 & 5 is Good

Here is the code:

Sub open_song2()

' Row = ActiveCell.Row
' f1 = Cells(Row, 1).Value
f1 = "sample.ppt"
pptDir = "G:\"
pptpath = pptDir & f1

On Error Resume Next ' Defer error trapping.
Set PPApp = GetObject(, "Powerpoint.Application")
If Err.Number <> 0 Then
' MsgBox "Powerpoint was not open"
Set PPApp = CreateObject("Powerpoint.Application")
Err.Clear ' Clear Err object in case error occurred.
Else
' MsgBox "Powerpoint was already open"
End If

PPApp.Parent.Windows(1).Visible = True
PPApp.Activate
Set PPPres1 = PPApp.Presentations.Open(pptpath, , , True)

'AppActivate ("Powerpoint.Application")
' PPApp.Visible = True
PPPres1.Visible = True
PPPres1.Activate

End Sub
 
T

Tushar Mehta

Maybe, it is a bug, or it might be something peculiar to your system.
In general, I am not surprised if my attempts to activate and make
various programs /windows the currently active one are not successful.

That said, you may want to restore error handling after the
createobject statement. As it stands, you are getting no help from VBA
in detecting errors.

For example, the PowerPoint application has no parent property. Not
according to help and not according to VBE Intellisense.

Also, you may want to try the AppActivate statement. However make it
AppActivate PPApp.Caption

If you declared PPApp as of type PowerPoint.Application, VBE
Intellisense will help you figure out what are legitimate
properties/methods.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

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