Consulting

Results 1 to 8 of 8

Thread: Shyam Pillai's ScreenUpdating with Office 2016

  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location

    Shyam Pillai's ScreenUpdating with Office 2016

    Shyam Pillai has a nice piece of PP code to turn off screen updating:

    http://skp.mvps.org/ppt00033.htm

    Does anyone know the Office 2016 (16.0) class name? I guessed at some but I guess I'm not a good guesser.

    I do get a hwnd, but it fails on LockWindowUpdate



    Get handle to the main application window using ClassName
            Select Case VersionNo
            Case "8"  ' For PPT97:
                hwnd = FindWindow("PP97FrameClass", 0&)
            Case "9"  ' For PPT2K:
                hwnd = FindWindow("PP9FrameClass", 0&)
            Case "10" ' For XP:
                hwnd = FindWindow("PP10FrameClass", 0&)
            Case "11" ' For 2003:
                hwnd = FindWindow("PP11FrameClass", 0&)
            Case "12" ' For 2007:
                hwnd = FindWindow("PP12FrameClass", 0&)
            Case "14" ' For 2010:
                hwnd = FindWindow("PPTFrameClass", 0&)
            Case "15" ' For 2013:
                hwnd = FindWindow("PPTFrameClass", 0&)
            Case "16" ' For 2016: -------------------------------------------------------------------- my guess
                hwnd = FindWindow("PPTFrameClass", 0&)
            Case Else
                Err.Raise Number:=vbObjectError + ERR_VERSION_NOT_SUPPORTED, _
                Description:="Newer version."
                Exit Property
            End Select
    
            If hwnd = 0 Then
                Err.Raise Number:=vbObjectError + ERR_NO_WINDOW_HANDLE, _
                Description:="Unable to get the PowerPoint Window handle"
                Exit Property
            End If
    
            If LockWindowUpdate(hwnd) = 0 Then
                Err.Raise Number:=vbObjectError + ERR_WINDOW_LOCK_FAIL, _
                Description:="Unable to set a PowerPoint window lock"
                Exit Property
            End If
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Update:

    I used winlister from http://www.nirsoft.net/utils/winlister.html

    The class name does seem to be PPTFrameClass (I had a lucky guess)


    So for some reason the LockWindowUpdate(hwnd) returns a 0
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    I figured it out

    I had my Booleans reversed in the calling module

    Shyam Pillai's code works fine
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4

    Question Please send me the Full Code

    Quote Originally Posted by Paul_Hossler View Post
    I figured it out

    I had my Booleans reversed in the calling module

    Shyam Pillai's code works fine


    Hi Paul,
    I am struggling to LockWindowUpdate for PowerPoint 2016.
    Could you please send me the changes in code you have done to execute for yourself.

    What is the classname instead of "PPTFrameClass"?

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    This is what I have


    Option Explicit
      
    ' --------------------------------------------------------------------------------
    ' Copyright ?1999-2009, Shyam Pillai, All Rights Reserved.
    ' --------------------------------------------------------------------------------
    ' You are free to use this code within your own applications, add-ins,
    ' documents etc but you are expressly forbidden from selling or
    ' otherwise distributing this source code without prior consent.
    ' This includes both posting free demo projects made from this
    ' code as well as reproducing the code in text or html format.
    ' --------------------------------------------------------------------------------
    ' UserDefined Error codes
    Const ERR_NO_WINDOW_HANDLE As Long = 1000
    Const ERR_WINDOW_LOCK_FAIL As Long = 1001
    Const ERR_VERSION_NOT_SUPPORTED As Long = 1002
    
    ' API declarations for FindWindow() & LockWindowUpdate()
    ' Use FindWindow API to locate the PowerPoint handle.
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
          (ByVal lpClassName As String, _
           ByVal lpWindowName As Long) As Long
    
    ' Use LockWindowUpdate to prevent/enable window refresh
    Declare Function LockWindowUpdate Lib "user32" _
          (ByVal hwndLock As Long) As Long
    ' 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)
          Static hWnd As Long
          Dim VersionNo As String
    
        ' Get Version Number
          If State = False Then
            VersionNo = Left(Application.Version, InStr(1, Application.Version, ".") - 1)
    
            ' Get handle to the main application window using ClassName
            Select Case VersionNo
            Case "8"  ' For PPT97:
                hWnd = FindWindow("PP97FrameClass", 0&)
            Case "9"  ' For PPT2K:
                hWnd = FindWindow("PP9FrameClass", 0&)
            Case "10" ' For XP:
                hWnd = FindWindow("PP10FrameClass", 0&)
            Case "11" ' For 2003:
                hWnd = FindWindow("PP11FrameClass", 0&)
            Case "12" ' For 2007:
                hWnd = FindWindow("PP12FrameClass", 0&)
            'For 2010 you need to add this:
            Case "14" ' For 2010:
                hWnd = FindWindow("PPTFrameClass", 0&)
            Case "16" ' For 2016
                hWnd = FindWindow("PPTFrameClass", 0&)
    
            Case Else
                Err.Raise Number:=vbObjectError + ERR_VERSION_NOT_SUPPORTED, _
                Description:="Supported for PowerPoint 97/2000/2002/2003 only."
                Exit Property
            End Select
            If hWnd = 0 Then
                Err.Raise Number:=vbObjectError + ERR_NO_WINDOW_HANDLE, _
                Description:="Unable to get the PowerPoint Window handle"
                Exit Property
            End If
            If LockWindowUpdate(hWnd) = 0 Then
                Err.Raise Number:=vbObjectError + ERR_WINDOW_LOCK_FAIL, _
                Description:="Unable to set a PowerPoint window lock"
                Exit Property
            End If
          Else
            ' Unlock the Window to refresh
            LockWindowUpdate (0&)
            UpdateWindow (hWnd)
            hWnd = 0
          End If
    End Property
    
    

    Sample usage


        ScreenUpdating = False
        
        oSelectedShape.PickUp
        
        For Each oSlide In ActivePresentation.Slides
            For Each oShape In oSlide.Shapes
                If oShape.Type = oSelectedShape.Type Then
                    oShape.Apply
                End If
            Next oShape
        Next oSlide
        
        ActiveWindow.Selection.Unselect
        
        ScreenUpdating = True
    
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Hi Paul,

    This is the same code as mentioned by Shyam Pillai. But it is not working with the Office 2016.
    Last edited by sujeetsingh; 05-07-2019 at 02:38 AM.

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    It does work in 2016. Why do you think it doesn't - are you getting an error?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    It does not lock the PowerPoint Presentation. In a debug mode executed below line but I can edit the shapes and text in presentation.

    If LockWindowUpdate(hWnd) = 0

    Code is working fine with the Office 2010.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •