Suppress screen redraw during macro execution

  • Thread starter Thread starter T Lavedas
  • Start date Start date
T

T Lavedas

I have a script that uses the PPT object model to create a set of
slides from a formatted text file. It works fine, except it would be
nice to speed it up a bit. I have searched for a way to keep PPT from
redrawing the display (in the edit pane) with each operation as one
way to improve performance. I'm pretty sure Excel supports this, but
can't remember what property controls that and can't find it in the
PPT object model.

I've searched the help files and googled this group and the web, but
to no avail. So, can someone put me out of my misery? Is there one
(and what is it) or should I just be satisfied with what I've got?

Thanks,

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
http://skp.mvps.org/ppt00033.htmshould get you going, or rather not until
you are ready.

--
Bill Dilworth
A proud member of the Microsoft PPT MVP Team
Users helping fellow users.http://billdilworth.mvps.org
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
vestprog2@ Please read the PowerPoint FAQ pages.
yahoo. They answer most of our questions.
com www.pptfaq.com

Thanks - that is what I suspected, but needed confirmation. (What a
truly integrated package the Office suite is --- not.)

This code would be very helpful, if I were programming in VBA.
Unfortunately, I am using an HTA that accesses the PPT object model.
I'm not certain this will apply because of the system API calls, at
least not within my 'effort' budget. Thanks, anyway.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
Does your script rely on selecting anything? That can slow things down.
Bigtime.

If so, show us some example code and we'll try to get around that.

Another approach is to drive PPT w/o a visible window (not sure if you can do
this from script vs VB/VBA)

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

I am not using any Selects. I am referencing text within a TextRange
using Characters() and then adjusting the Font parameters, for
example ...

....
Const clrWhite = &hFFFFFF, clrBlack = 0 , clrYellow = &hFFFF&

On Error Resume Next
set oPP = GetObject("","PowerPoint.Application")
nErr = Err.Number
On Error Goto 0
if nErr <> 0 then
set oPP = CreateObject("PowerPoint.Application")
end if

oPP.Visible = True
set oPresentation = oPP.Presentations.Open(sPath & sMasterName)

with oPresentation ' oPP.ActivePresentation
...
nChrs = 1
for nLine = i to iStop
aLine = Split(aText(nLine), "*")
With .Slides(nSlide).Shapes.Item(2).TextFrame.TextRange
.Characters(nChrs, 0).Text = aLine(0) & "*" & Chr(11)
with .Characters(nChrs, .Characters.Count - nChrs + 1).Font
.Size = 26
.Color.RGB = clrWhite
.Italic = False
end with
nChrs = .Characters.Count + 1
.Characters(nChrs, 0).Text = aLine(1) & vbNewline
with .Characters(nChrs, .Characters.Count - nChrs + 1).Font
.Size = 30
.Color.RGB = clrYellow
.Italic = True
end with
end with
next
...
end with

As far as setting the PPT window visibility - it must be visible. If
it's not set to true, the Open fails. If an attempt is made to change
it after the blank presentation is opened, it throws a "... visibility
cannot be changed error" (v2003).

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
OK, no selects. One line of retreat cut off. ;-)

But try NOT setting the App visible then use

set oPresentation = oPP.Presentations.Open(sPath & sMasterName,,False)

That'll open the presentation w/o a window, so there's no need for the app to be
visible.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

Sorry, no cigar - That throws a "Presentation Open: Invalid Request.
The PowerPoint Frame window does not exist." error when run from a
script external to PPT, if PPT is not open and visible. It refreshes
the screen, if there is one open.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
Rats. I suppose it's a scripting vs VB/VBA issue. I wonder why the behavior'd be
different for scripting though.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

Can't say for certain, but it seems PPT must have a window to from
which to work - and scripting just doesn't provide one.

Thanks for the suggestions, though. It was worth the effort, just to
be certain it wasn't possible. I'll have to live with the latency -
it's not too bad - especially when I consider how long it took to
format the slides by hand before I built the script (15-40 seconds
verses 15-40 minutes). I do this almost weekly, so it won't be long
before it's paid big dividends - even running 'slowly'.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
[snippasnippasnippasnip]
Can't say for certain, but it seems PPT must have a window to from
which to work - and scripting just doesn't provide one.

It does seem odd.  You can automate it hidden from other apps or VB, and as long as you
open the presentation windowless (what the final False parameter I mentioned earlier
specifies) and don't try to do anything that explicitly refers to the window, you should
be ok.

set oPresentation = oPP.Presentations.Open(sPath & sMasterName,,False)

<wild_speculation>
Could there be something about the way VBS passes parms to other apps?

Might ALL parms have to be explictly specified, as in:

set oPresentation = oPP.Presentations.Open(sPath & sMasterName,False,False)

</wild_speculation>

That doesn't help. It appears Powerpoint MUST have a window. It
still errors out on that line, failing to open the file.
One other possibility is to launch the app minimized if VBS permits that. There's a
window then, but it's not visible (other than on the taskbar and no fair peeking).  No
visible window, nothing to refresh so it should run more quickly.
{snip}

As far as I can tell, that doesn't have any impact. HOWEVER, after
restructuring the script to workaround a bug I encountered running the
script under Win2K (but not in XP - both running 2003SP2, though the
XP one is a commercial package and the 2K a student version - I
haven't compared the build numbers) the script ran lightning fast ---
at first. BUT, the longer it ran (looping through multiple input
files, creating a set of slides for each into separate ppt
presentations), the slower it got. It started at 15 to 20 per minute,
but slowed to fewer than one a minute at about the 90th file. It had
nothing to do with the content of the file, for I aborted the loop and
retried stating at the 98th file in blocks of 10 and each group
completed in mere seconds (whether fullscreen or minimized). It is
truly mind boggling.
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ:  www.pptfaq.com
PPTools:  www.pptools.com
================================================

My wild speculation is that PPT either has a massive memory leak
(though I can't detect it using the Task Manager) or else the OS keeps
relegating fewer and fewer CPU cycles the longer PPT is running. This
seems to be the more likely of my speculations, as the CPU usage was
unmeasurable during the earlier run when it bogged down at file number
98. When I retested in blocks of ten files, the usage would spike to
75-80 percent while the script was running.

So, I don't see any need to pursue the screen redraw issue any longer,
since it appears the major problem is related more to how the OS is
allocating time to its various processes.

Well - while composing this a thought came to me - maybe the script
looping was causing the system to get bound up with too many pending
processes. Sooooo - I added a half-second sleep after processing a
file in the loop to give pending threads access to the processor.
That did the trick. It is now handling more than 30 files a minute.
I can't ask for more than that.

Thanks for the help, but my overriding problem does not seem to be PPT
related.

Tom Lavedas
===========
 
Back
Top