PowerPoint OLE automation without making the window visible

M

Mike Hearn

Hi,

I'm sure this must be an FAQ so apologise in advance if you guys answer
it a lot, but I couldn't find anything on it in the FAQs I found on
Google, so here goes ....

I'm trying to get the textual contents of a presentation into another
app via OLE automation. I've got some code to do this and it works fine
*but* it requires the main PowerPoint window to be visible. This is a
big issue as I don't want it to disturb the user on the workstation
while my program is indexing these presentations so having it display,
index, then become invisible again is clearly unacceptable.

I have a nasty feeling the answer will be "you can't do that" as when I
try and open a presentation while the main window is invisible I get
this error:

"Invalid request. The PowerPoint Frame window does not exist."

If I force the window to be created (?) by setting Visible to FALSE, I
get this message:

"Invalid request. Hiding the application window is not allowed."

Gosh, I am naughty!

This is confusing because the exact same construct works fine in Word: I
can open a document, grab the text and close it without anything
appearing on screen.

Any ideas?

thanks -mike
 
S

Shyam Pillai

Mike,
You can certainly automate PowerPoint while keeping it invisible. In fact it
is more efficient to do so.

Dim AppPPT As Object
Dim oPres As Object
Set AppPPT = CreateObject("PowerPoint.Application")

' Though I've explicitly opened the presentation without window,
' if PowerPoint is invisible a Open call will automatically open it w/o a
window.
Set oPres = AppPPT.Presentations.Open("c:\sample.ppt", , , False)

On Error Resume Next
With oPres
For I = 1 To .Slides.Count
' ----
' ----
' ----
Next I
End With
oPres.Close
Set oPres = Nothing
AppPPT.Quit
Set AppPPT = Nothing

You should avoid common pitfalls:
- Ensure that you code does have bits which invoke 'Selection' calls. When
there is no UI the concept of selection does not exist.
- Ensure that you do not reference 'active' global objects like
ActivePresentation, ActiveWindow etc.
- Fully qualify all objects.
- If you are going to print from PowerPoint, turn off background printing.
 
M

Mike Hearn

Shyam said:
Mike,
You can certainly automate PowerPoint while keeping it invisible. In fact it
is more efficient to do so.

Dim AppPPT As Object
Dim oPres As Object
Set AppPPT = CreateObject("PowerPoint.Application")

' Though I've explicitly opened the presentation without window,
' if PowerPoint is invisible a Open call will automatically open it w/o a
window.
Set oPres = AppPPT.Presentations.Open("c:\sample.ppt", , , False)

Thanks Shyam. I'm not using VBScript, but rather Java, and this line
made me notice what I was doing wrong: you have to specify you don't
want a window in the open call using an optional parameter. I set that,
and now it works.

thanks -mike
 

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