PowerPoint Presentation Password RRS feed

  • Question

  • Hello everyone!

    I am trying to create a macro that password protects a PowerPoint presentations, and if possible, multiple presentations in a folder.

    I am using PowerPoint 2010.

    In one of the presentations I created a UserForm1 that contains a TextBox1 and a CommandButton1.

    When I run the macro, the UserForm1 pops up, and you can enter in a password, but it gives me the error "Method or data member not found" when I run it.

    Here is what I have so far:

    Private Sub UserForm_Click()
    End Sub
    Private Sub CommandButton1_Click()
    Dim pres As Presentation
        For Each pres In Presentations
            If pres.ProtectContents = True Then 'error is here
               pres.UnProtect Password:=TextBox1.Text
               pres.Protect Password:=TextBox1.Text
            End If
        Next pres
        Unload Me
    End Sub
    Thanks in advance!

    P.S. I want the password to apply to modifying the presentation only.
    • Edited by Turkwise Tuesday, July 31, 2012 3:01 PM
    Tuesday, July 31, 2012 2:59 PM


  • Hi Turkwise,

    Thanks for posting in the MSDN Forum.

    Presentation has no ProtectContents property/method. As usual, we can use Application's ProtectedViewWindows's Open method to Open the presentation which you want protected. If you don't want somebody to edit your presentation you can modify the ProtectedViewWindowBeforeEdit to approach your goal. However, we can't subscribe event in Module of the VBA. You need create Class or Form to handle this. Following is a sample:

    Private WithEvents app As Application
    Private flag As Boolean
    Private Sub app_ProtectedViewWindowBeforeEdit(ByVal ProtViewWindow As ProtectedViewWindow, Cancel As Boolean)
        Cancel = True
    End Sub
    Private Sub CommandButton1_Click()
        Set app = Application
        If TextBox1.Text = "123456" Then
            app.ProtectedViewWindows.Open "C:\******.pptx"
            flag = True
            flag = False
        End If
    End Sub
    Private Sub UserForm_Initialize()
        flag = False
    End Sub

    I hope it can help you.

    Have a good day,


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 1, 2012 7:00 AM