VBA代码取消保护打开的PowerPoint演示文稿,然后在保存之前再次保护它?



我保护了一个PowerPoint演示文稿,防止用户修改它。但是我无法使用 VBA 来取消保护它。

我尝试在下面使用此代码,但它不起作用。它仅适用于不受保护的演示文稿。但是您必须从代码中删除 pw。

set p = pa.presentations.open(pth + pptname, pw)

假设您知道密码,您可以使用以下内容打开文件:

Presentations.Open("c:tempprotected_presentation.pptx::password::")

并使用例如在演示文稿上设置密码:

ActivePresentation.Password = "Hide_me"

[编辑以添加一个完整的测试工作示例,该示例假设演示文稿 C:\temp\testtest.pptx 已使用密码 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:temptest.pptx::opensesame::")
MsgBox oPPTPres.slides(1).Shapes(1).TextFrame.TextRange.Text
oPPTPres.Close
oPPTApp.Quit
End If
End Sub

最新更新