Macro to Determine If the Current Document Is Read-Only

Last reviewed: August 5, 1997
Article ID: Q126023
The information in this article applies to:

- Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c

SUMMARY

When you are writing a macro, you may need to know if the current document is open as a read-only document. This article includes a sample macro that you can use to determine whether the current document is read-only.

MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Sub Main
If InStr(WindowName$(), "(Read-Only)") <> 0 Or InStr(WindowName$(), \
 "(Copy)") <> 0 Then
MsgBox "File is read-only" End If
End Sub

If the current document was opened on a read-only basis, the WindowsName$() function will include the text "(Read-Only)" or "(Copy)." A document is opened on a read-only basis if the read-only file attribute is set or if another user has already opened the file with read-write privileges. A file can also be saved with the Read-Only Recommended option set, giving the user the option of opening the file on a read-only basis or not.

REFERENCES

"Microsoft Word Developer's Kit," for version 6.0, page 829


KBCategory: kbmacro
KBSubcategory: kbmacroexample
Additional reference words: 6.0 6.0a 6.0c winword read-only read only
word6 attribute copy setattr
Keywords : kbmacroexample kbmacro
Version : 6.0 6.0a 6.0c
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 5, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.