2
votes

I am opening a password protected Word document using the below macro in Excel, then I want to save a copy of the document without the password protection. Currently, I am still prompted for the original password when I try and open the newly saved document.

Dim DPObj
Dim DPApp As Object
Dim YourOwnPassword As String
Dim DocPath As String
DocSrcPath = "C:\Users\ADMIN\Desktop\Sources\SourceDoc.doc"
DocTgtPath = "C:\Users\ADMIN\Desktop\Targets\TargetDoc.doc"
YourOwnPassword = "TestPWD"
Set DPApp = CreateObject("word.Application")
'Open Password enabled document
DPDoc = DPApp.Documents.Open(DocSrcPath, PasswordDocument:=YourOwnPassword)
'Make some changes to the document. 
'Save the edited document without a password
DPApp.ActiveDocument.SaveAs2 DocTgtPath

Does anybody know how to make it so that the TargetDoc.doc is not still password protected?

1
Why doesn't the current code work?Wolfie
When i open the new document it is prompting for the password "TestPWD". Which i don't wanted toUdhayakumar
You want to remove the password in the saved document? Try using DPApp.Unprotect before saving.Vincent G
@Vincent G Getting error ** Run-time error '438' Object doesn't support this property or method **Udhayakumar
Sorry, I mean DPApp.ActiveDocument.UnprotectVincent G

1 Answers

2
votes

Using a blank password should work:

DPApp.ActiveDocument.SaveAs2 DocTgtPath, Password:=""