VBA code to unprotect a opened powerpoint presentation, then protect it again before saving it?

后端 未结 1 677
情书的邮戳
情书的邮戳 2021-01-25 18:41

I protected a power point presentation from user modifying it. However I can\'t use VBA to un-protect it.

I tried to use this code below but it doesn\'t work. It only w

1条回答
  •  囚心锁ツ
    2021-01-25 19:09

    Assuming you know the password, you can open the file with something like:

    Presentations.Open("c:\temp\protected_presentation.pptx::password::")
    

    And set the password on a presentation with eg:

    ActivePresentation.Password = "Hide_me"
    

    [editing to add a complete tested, working example that assumes a presentation C:\temp\testtest.pptx that's been saved with password opensesame]

    Sub TestTest()
    
        Dim oPPTApp As Object
        Dim oPPTPres As Object
    
        Set oPPTApp = CreateObject("PowerPoint.Application")
    
        If Not oPPTApp Is Nothing Then
            Set oPPTPres = oPPTApp.presentations.Open("C:\temp\test.pptx::opensesame::")
            MsgBox oPPTPres.slides(1).Shapes(1).TextFrame.TextRange.Text
            oPPTPres.Close
            oPPTApp.Quit
        End If
    End Sub
    

    0 讨论(0)
提交回复
热议问题