Microsoft KB Archive/124002

= Microsoft Knowledge Base =

MXL5: ChangeFileAccess Command Ignored
Last reviewed: June 4, 1997

Article ID: Q124002

5.00 5.00a MACINTOSH kbprg kbcode kbprb

The information in this article applies to:


 * Microsoft Excel for the Macintosh, versions 5.0, 5.0a

SYMPTOMS
When you use a Visual Basic, Applications Edition, command to change the file access privileges of an open Microsoft Excel workbook file, the command is ignored and the file access privileges of the workbook are unchanged.

Example
To change the file access privileges of an open workbook, use the following command:

ActiveWorkbook.ChangeFileAccess xlReadWRite When you run this command, Microsoft Excel should display a dialog box in which you can enter a password. Once you enter a password, the file will be open for Read/Write access. When this procedure occurs successfully, the words Read-Only are removed from the title bar of the document window.

This command may be ignored every other time you run it.

CAUSE
This behavior occurs when the procedure that contains the ChangeFileAccess method is within the workbook that the procedure is changing. If the procedure is in a workbook other than the workbook that you are changing, the file access privilege is changed as expected.

Note that this problem does not occur with a workbook that does not contain a password.

WORKAROUND
To work around this problem, use either of the methods below.

Microsoft provides examples of Visual Basic procedures 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 Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line -continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."

Method 1: Specify the password along with the macro command, as in the

following example

ActiveWorkbook.ChangeFileAccess mode:=xlReadWrite, _ writePassword:="mypassword"

where mypassword is the password that you used to protect the workbook.

When you use this method, the dialog box is not displayed for password entry, but file access privileges are changed successfully. Method 2: Run the command a second time. (This command appears to be

ignored at every odd numbered attempt, so running it again should allow it to work correctly.)

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.