none
Document.SaveAs2 of document loaded using a password RRS feed

  • Question

  • If I open a password-protected docx file (requiring password to open) from a local drive in Word 2016, and then execute ActiveDocument.SaveAs2 fileName="somefilename.docx" (note that I have omitted the password argument to SaveAs2), I can't figure out any way to open the resulting somefilename.docx. It demands a password when I attempt to open it, but neither the previous document password nor a blank password works. The file appears to be ruined.

    Any ideas how I'm supposed to be saving under a new name without destroying the file? Ideally it would be saved using the same password that the ActiveDocument was opened with -- after all, that's what you get if you use the menus to simply the save the document under a different name rather than using SaveAs2. But I would also be interested in a way that doesn't completely destroy the content.

    Thanks,
    David

    Thursday, August 24, 2017 6:12 PM

All replies

  • Try something like:

    ActiveDocument.SaveAs2 FileName:="somefilename.docx", FileFormat:=wdFormatXMLDocument, Password:=""

    to remove the password, or:

    Dim wdDoc As Document
    Const StrPwd As String = "MyPassword"
    Set wdDoc = Documents.Open(FileName:="sourcefilename.docx", PasswordDocument:=StrPwd)
    'Do your processing here
    wdDoc.SaveAs2 FileName:="somefilename.docx", FileFormat:=wdFormatXMLDocument, Password:=StrPwd

    to preserve it.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, August 25, 2017 12:29 AM
  • Hi dmartin9802,

    I failed to reproduce your issue. The password does not change after using SaveAS2 in my test. I suggest you check if there is a Case-insensitive issue. You could also try to save as the document manually and check if the issue still exists.

    Best Regards,

    Terry

    Friday, August 25, 2017 8:57 AM
  • Thanks Paul!. I'd like to preserve the password, but my script does not know the password the file was loaded with, so I can't provide it using a Password:= argument. Unless there is some way for the script to grab it... which I find highly doubtful.

    Friday, August 25, 2017 5:10 PM
  • Oh man, now I can't reproduce it either. I was pretty careful in my testing yesterday before posting, though. So there's some other factor I don't understand. I'll post again if I figure out what it is.

    Thanks very much,
    David

    Friday, August 25, 2017 5:20 PM
  • In that case, simply use:

    ActiveDocument.SaveAs2 FileName:="somefilename.docx", FileFormat:=wdFormatXMLDocument


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, August 26, 2017 5:20 AM