The information in this article applies to:
SUMMARYThis article describes how to determine if a file has an attribute of read- only, and how to determine if a file is opened as read-only using Microsoft Visual Basic for Applications code. MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspYou can determine if a file has an attribute of read-only or if the file is opened as read-only by using the macros described in this article. Steps to Set a File to Read-Only Using Windows
Steps to Set a File to Read-Only using the Macintosh
Sample Visual Basic ProceduresExample 1: A Macro to Determine if File's Read-Only Attribute is SetThe following macro will determine if a file's read-only attribute is set. Open the file you created above, and then type the macros below in a module sheet.
If you followed steps 1 - 5 in the "Steps to Set a File to Read-Only using
Windows" section, when you run the macro in Example 1, you will receive a
message box with the "File is Read-only" message.
Note: If you are working on a Macintosh, substitute the harddisk's name and "test" for "c:\test.xls". For example, if your harddisk's name is "HD", you would type GetAttr("HD:test"). Example 2: A Macro to Determine if Active Workbook is Opened as Read-Only The following macro will determine if the active workbook is opened as read-only.
If you open the workbook created in step 1 of the "Steps to Set a File to
Read-Only using Windows" section, when you run the macro from Example 2,
you will receive a message box with the "File was opened as read-only"
message.
REFERENCESFor additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base: Q163435 VBA: Programming Resources for Visual Basic for Applications Additional query words: 5.00a 5.00c 7.00a 8.00 readonly howto
Keywords : kbprg kbdta kbdtacode PgmHowto KbVBA |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |