WorkbookBase.ChangeFileAccess Method

Changes the access permissions for the workbook. This might require an updated version to be loaded from the disk.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Sub ChangeFileAccess ( _
    mode As XlFileAccess, _
    writePassword As Object, _
    notify As Object _
)
public void ChangeFileAccess(
    XlFileAccess mode,
    Object writePassword,
    Object notify
)

Parameters

  • writePassword
    Type: System.Object

    Specifies the write-reserved password if the file is write reserved and Mode is xlReadWrite. Ignored if there is no password for the file or if Mode is xlReadOnly.

  • notify
    Type: System.Object

    true to notify the user if the file cannot be immediately accessed.

Remarks

If you have a file open in read-only mode, you do not have exclusive access to the file. If you change a file from read-only to read/write, Microsoft Office Excel must load a new copy of the file to ensure that no changes were made while you had the file open as read-only.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Examples

The following code example displays a message if the ReadOnlyRecommended property is true and the ReadOnly property is false, and then prompts the user to set the file access to read-only by calling the ChangeFileAccess method.

This example is for a document-level customization.

Private Sub MakeWorkbookReadOnly()
    If Me.ReadOnlyRecommended AndAlso Not Me.ReadOnly Then 
        ' Change the access level of the document to read-only   
        ' if the user clicks yes. 
        If MessageBox.Show("Set this document to read-only?", _
            "Sample", MessageBoxButtons.YesNo) = DialogResult.Yes Then 
            Me.ChangeFileAccess(Excel.XlFileAccess.xlReadOnly, Notify:=False)
        End If 
    End If 
End Sub
private void MakeWorkbookReadOnly()
{
    if (this.ReadOnlyRecommended && !this.ReadOnly)
    {
        // Change the access level of the document to read-only if the user  
        // clicks yes. 
        if (MessageBox.Show("Set this document to read-only?",
            "Sample", MessageBoxButtons.YesNo) == DialogResult.Yes)
        {
            this.ChangeFileAccess(Excel.XlFileAccess.xlReadOnly,
                 false);
        }
    }
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace