Showing error when password protected OpenXml Word document get resaved as a password protected binary Word in office 2010

calendar_today Asked Feb 25, 2016
thumb_up 4 upvotes
history Updated April 14, 2026

Direct Answer

With the code you provided I am also not able to correctly set the read/write passwords. It seems that Word is not able to change the save format and retain the read/save…. This is a 21-line Word VBA snippet, ranked #24th of 32 by community upvote score, from 2016.


The Problem (Q-score 8, ranked #24th of 32 in the Word VBA archive)

The scenario as originally posted in 2016

In microsoft word i have created openxml.doc(*.docx) file given credentials ‘abc’ as Readpassword and ‘xyz’ as WritePassword.

Now i have to convert openxml.doc to binary.doc(WdSaveFormat=0) the document is created sucessfully as Binary.doc using below code

// Convert OpenXml.doc into binary.doc    
Convert(@"C:TestOpenXml.doc", @"C:Testbinary.doc", WdSaveFormat.wdFormatDocument);

// Convert a Word .docx to Word 2003 .doc
public static void Convert(string input, string output, WdSaveFormat format)
{
    // Create an instance of Word.exe
    Word._Application oWord = new Word.Application();

    // Make this instance of word invisible (Can still see it in the taskmgr).
    oWord.Visible = false;

    // Interop requires objects.
    object oMissing = System.Reflection.Missing.Value;
    object isVisible = true;
    object readOnly = false;
    object oInput = input;
    object oOutput = output;
    object oFormat = format;
    object oNewPassword = "xyz";
    object oOldPassword = "abc";
    object test = null;

    try
    {
        // Load a document into our instance of word.exe
        // suppose password "abc"
        Word._Document oDoc = oWord.Documents.Open(ref oInput, ref oMissing,
                                 ref readOnly, ref oMissing, oOldPassword,
                                 ref oMissing, ref oMissing, oNewPassword,
                                 ref oMissing, ref oMissing, ref oMissing,
                                 ref isVisible, ref oMissing, ref oMissing,
                                 ref oMissing, ref oMissing);

        // Make this document the active document.
        oDoc.Activate();

        // Save this document in Word 2003 format.
        oDoc.SaveAs(ref oOutput, ref oFormat, ref oMissing,
                    ref oOldPassword, ref oMissing,
                    oNewPassword, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing);
        Console.WriteLine(test);
        // Always close Word.exe.
        oWord.Quit(ref oMissing, ref oMissing, ref oMissing);
    }
    catch (Exception)
    {
        throw;
    }
}

But when try to open document manually or from code it accepts Readpassword(‘abc’) as shown below

enter image description here

but when tries to give WritePassword(‘xyz’) it doesnt accept and shown password incorrect error.Please check below screenshots

enter image description here

enter image description here

Why community consensus is tight on this one

Across 32 Word VBA entries in the archive, the accepted answer here holds niche answer (below median) status — meaning voters are unusually aligned on the right fix.


The Verified Solution — niche answer (below median) (+4)

21-line Word VBA pattern (copy-ready)

With the code you provided I am also not able to correctly set the read/write passwords. It seems that Word is not able to change the save format and retain the read/save passwords at the same time (this might be a bug or simple an unsupported scenario).

However, there is a very simple workaround: Just save the document temporarily without password and then set the password again:

public static void Convert(string input, string output, Word.WdSaveFormat format)
{
    // Create an instance of Word.exe>
    var oWord = new Word.Application();

    // open the protected document
    var oDoc = oWord.Documents.Open(input, PasswordDocument: "abc", WritePasswordDocument: "xyz");

    // save the document without password first
    oDoc.SaveAs(FileName: output, Password: "", WritePassword: "");

    // close and reopen
    oDoc.Close();
    oDoc = oWord.Documents.Open(output);

    // set the password
    oDoc.SaveAs(FileName: output, FileFormat: format, Password: "abc", WritePassword: "xyz");

    oWord.Quit();
}


When to Use It — classic (2013–2016)

Ranked #24th in its category — specialized fit

This pattern sits in the 79% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the Word VBA archive for a higher-consensus alternative.

What changed between 2016 and 2026

The answer is 10 years old. The Word VBA object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.

help
Frequently Asked Questions

This is a below-median answer — when does it still fit?
expand_more

Answer score +4 vs the Word VBA archive median ~4; this entry is niche. The score plus 8 supporting upvotes on the question itself (+8) means the asker and 3 subsequent voters all validated the approach.

Does the 21-line snippet run as-is in Office 2026?
expand_more

Yes. The 21-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

Published around 2016 — what’s changed since?
expand_more

Published 2016, which is 10 year(s) before today’s Office 2026 build. The Word VBA object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which Word VBA pattern ranks just above this one at #23?
expand_more

The pattern one rank above is “Can Microsoft.office.interop.word.dll work without installing office?”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 8, Answer-score 4, original post 2016, ranked #24th of 32 in the Word VBA archive. Last regenerated April 14, 2026.