Name

workbook.ChangeFileAccess(Mode, [WritePassword], [Notify])

Synopsis

Changes a workbook to read-only or read/write access.

Argument

Settings

Mode

xlReadOnly changes the access to read-only; xlReadWrite changes access to read/write.

WritePassword

The password required for write access if the workbook is write-protected.

Notify

True displays a message if the file is not available for read/write access, perhaps because it is open for another user; False does not notify. Default is True.

Switching a read-only workbook to read/write may reload the file in Excel. The following code demonstrates changing file-access modes on the current workbook:

' Save changes.
ThisWorkbook.Save
' Change to read-only.
ThisWorkbook.ChangeFileAccess xlReadOnly
' Change back. (May reload file.)
ThisWorkbook.ChangeFileAccess xlReadWrite

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.