|
OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy |
| PowerPoint VBA Equivalent of Application.ScreenUpdating |
|
|
Excel & Word have the ScreenUpdating method thru which a developer can lock the main window from unnecessarily redrawing itself whilst the macro is being executed. This method is however not present in PowerPoint. If left alone, redrawing is not only ugly on the eyes it also takes more time for the macro to reach completion. Hence I created this generic wrapper to lock the window updates. ' --------------------------------------------------------------------------------
' UserDefined Error codes Const ERR_NO_WINDOW_HANDLE As Long = 1000
' Use FindWindow API to locate the PowerPoint handle. Declare Function FindWindow Lib "user32" Alias "FindWindowA"
_
Declare Function LockWindowUpdate Lib "user32" _ ' Use UpdateWindow to force a refresh of the PowerPoint window Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long Property Let ScreenUpdating(State As Boolean)
If State = False
Then
' Get handle to the main application window using ClassName
Select Case VersionNo hwnd
= FindWindow("PP97FrameClass", 0&) hwnd = FindWindow("PP9FrameClass", 0&) Case "10"
' For XP: Case "11"
' For 2003: Case "12"
' For 2007: Case "14"
' For 2010:
Case Else ' Unlock the Window to refresh LockWindowUpdate (0&) UpdateWindow
(hwnd) End If End Property
'Sample Usage: Sub LongProcessingSub() ' Lock screen redraw ScreenUpdating=False ' --- Long time consuming code ' Redraw screen again ScreenUpdating=True ' Also see below article for another example of usage of the code End Sub
|
|
|
It's fairly simple to open a PowerPoint file (*.ppt) for editing using VBA code however opening a PowerPoint Show (*.pps) file for editing is altogether another matter. Use the Presentation.Open method and it defaults to open the file in Slide Show mode. This might not be desirable. The routine below illustrates a manner of woring around the default behaviour and opening the file for editing. The routine also illustrates the use of the ScreenUpdating property (code listed above). '
-------------------------------------------------------------------------------- Sub OpenPPSForEdit() On Error GoTo ErrHandle Dim pShow As Presentation ' See above article example for the code ScreenUpdating = False 'Open the show, however use additional flag - WithWindow set to FALSE Set pShow = Presentations.Open("C:\sample.pps",
_ pShow.NewWindow ScreenUpdating = True End Sub
|
|
Copyright 1999-2011 (c) Shyam Pillai. All rights reserved.