Search code examples
vbapowerpoint

PowerPoint VBA lock all shapes


Does anyone know how to lock all shapes from all slides in vba and also unlock in another macro?

I've the beggining but I can't find how to apply the lock function.

Sub test()
    On Error Resume Next
    For Each oSlide In ActivePresentation.Slides
        oSlide.Shapes.SelectAll
        xxx.locked
    Next
End Sub

Solution

  • Here we go

    Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Sub Lock()
    Dim oSlide As Slide
    Dim oShape As Shape
    Dim slideIndex As Long
    Set oSlide = Application.ActiveWindow.View.Slide
    oSlideIndex = oSlide.slideIndex
    
    On Error Resume Next
    For Each oSlide In ActivePresentation.Slides
    ActivePresentation.Slides(oSlide.slideIndex).Select
    Sleep (100)
    ActivePresentation.Slides(oSlide.slideIndex).Shapes.Range.Locked = msoTrue
    Next
    ActivePresentation.Slides(oSlideIndex).Select
    End Sub