【问题标题】:Open a password protected Word document in VBA在 VBA 中打开受密码保护的 Word 文档
【发布时间】:2017-02-16 21:18:57
【问题描述】:

我需要在 VBA 中打开受密码保护的 word 文档 它要求输入密码,如何通过代码打开 代码:

Dim DPDoc
Dim DPApp
Dim DPPath
DPPath = "C:\MyFolder\PwdProtectdFile.docx"
Set DPApp = CreateObject("word.Application")
' It is asking for the password here 
DPDoc = DPApp.Documents.Open(DPPath)

【问题讨论】:

    标签: vba excel ms-word


    【解决方案1】:

    只需添加一个参数:

    Dim YourOwnPassword As String
    YourOwnPassword = "TestPWD"
    DPDoc = DPApp.Documents.Open(DPPath, PasswordDocument:=YourOwnPassword)
    

    源:https://msdn.microsoft.com/en-en/library/office/ff835182.aspx

    【讨论】:

    • 我得到运行时错误'448'“未找到命名参数”所以我更改为 DPDoc = DPApp.Documents.Open(DPPath, Password = YourOwnPassword) 现在它仍然提示输入密码。好像没有考虑到。谁能帮忙
    • @udhayakumar :我的错,字面上看来应该是PasswordDocument 而不仅仅是Password!查看编辑
    猜你喜欢
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多