Microsoft KB Archive/275976

= Word document opens as read-only when you try to programmatically open the document =

Article ID: 275976

Article Last Modified on 1/29/2007

-

APPLIES TO


 * Microsoft Office Word 2007
 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition

-



This article was previously published under Q275976





SYMPTOMS
When you try to programmatically open a Microsoft Word document, the document opens as a read-only document and you cannot edit the document.

When you add the code ReadOnly:=False the document still opens as a read-only document.

When you open the same document using the Open command, the following message appears:

should be opened as read-only unless changes to it need to be saved. Open as read-only?

You can open the document for editing by clicking Yes on the message.



CAUSE
This problem occurs because Visual Basic opens any document with the ReadOnlyRecommended attribute set to true as a read-only document, even if you attempt to set the ReadOnly attribute to false.

Note The following example applies to Word 2003 and 2002:  Start Word, and then create a new document. On the Tools menu, click Options. In the Options dialog box, on the Security tab, click to select the Read-only recommended check box. Save the document as C:\Test.doc. Close the document. Press ALT+F11 to start the Visual Basic editor.</li> On the Insert menu, click Module.</li>  In the Module sheet, type the following code: Sub Test

Documents.Open FileName:=&quot;C:\Test.doc&quot;, ReadOnly:=False

End Sub </li> Press ALT+F11 to return to Word.</li> On the Tools menu, point to Macro, and then click Macros.</li> In the Macro name list, click Test, and then click Run.</li></ol>

The document opens as a read-only document.

<div class="workaround_section">

WORKAROUND
To work around this problem, use the following Word Basic macro instead of the Visual Basic macro shown in step 8 of the &quot;Cause&quot; section of this article: Sub Test

WordBasic.FileOpen Name:=&quot;C:\Test.doc&quot;

End Sub With this macro the file can be edited after it opens.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Additional query words: WD2002 WD2003 WD2007

Keywords: kbbug kbpending KB275976

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.