Yes. In Excel VBA, pass ReadOnly:=True to Workbooks.Open to open a workbook without saving changes back to its original file. For example: Set sourceWb = Workbooks.Open(Filename:=filePath, ReadOnly:=True). You can still read cells and work with the opened workbook in memory; read-only is a safeguard against overwriting the source, not a security barrier.
What opening a workbook read-only means
When Excel opens a workbook read-only, it lets the current Excel session view and use the file while preventing that session from saving changes over the same source file. A macro can inspect sheets, read values, calculate results, or copy information elsewhere. If someone edits cells, those edits are normally not written back to the original workbook when it is closed without saving.
Read-only does not mean that the workbook is frozen in every respect. Excel may allow edits in the open copy, and a user can usually use Save As to create a separate file. Nor does read-only prevent another person or process from changing the original file. It simply controls how this particular open session treats the source workbook.
This option is useful for reporting macros, data imports, audits, and routine checks where a procedure should inspect a source file but must not accidentally replace it. It is also useful when a workbook is shared and the macro does not need to update the shared copy.
The Workbooks.Open argument
Workbooks.Open is Excel’s VBA method for opening a workbook. The ReadOnly argument accepts a Boolean value: use True to request read-only access and False to request normal access. Naming the argument, as in ReadOnly:=True, makes the intent clear and avoids relying on the position of optional arguments.
A compact example, assuming the workbook path is stored in filePath, is:
Set sourceWb = Workbooks.Open(Filename:=filePath, ReadOnly:=True)
The return value is a Workbook object, so assign it to a declared variable if the macro will refer to the opened file afterward. You can check the actual state with sourceWb.ReadOnly. That is useful when files might also be opened read-only because of permissions, a lock, or other conditions, rather than solely because the code requested it.
A complete macro example
This example opens a named workbook read-only, reads a cell from its Summary sheet, prints the value to the Immediate window in the VBA editor, and closes the source without saving. Change the sample path and sheet name to match your files.
Option Explicit
Sub ReadSourceWorkbook()
Dim filePath As String
Dim sourceWb As Workbook
Dim sourceWs As Worksheet
Dim errorText As String
filePath = "C:\Reports\Sales.xlsx"
On Error GoTo OpenFailed
Set sourceWb = Workbooks.Open( _
Filename:=filePath, _
UpdateLinks:=0, _
ReadOnly:=True, _
IgnoreReadOnlyRecommended:=True)
Set sourceWs = sourceWb.Worksheets("Summary")
Debug.Print sourceWs.Range("A1").Value
sourceWb.Close SaveChanges:=False
Exit Sub
OpenFailed:
errorText = Err.Description
On Error Resume Next
If Not sourceWb Is Nothing Then
sourceWb.Close SaveChanges:=False
End If
On Error GoTo 0
MsgBox "Could not read the workbook: " & errorText, vbExclamation
End Sub
Before running a macro, save a separate copy of any workbook you care about. VBA actions cannot be undone with Ctrl+Z. In this example, UpdateLinks:=0 tells Excel not to update external workbook links as it opens the file; it does not disable every kind of data connection or refresh operation. IgnoreReadOnlyRecommended:=True suppresses the recommendation prompt when a workbook has been marked as read-only recommended. It does not make an otherwise writable open read-only; that is the job of ReadOnly:=True.
Reading values after opening
Once the workbook is open, use the returned workbook variable to identify the source explicitly. For example, sourceWb.Worksheets("Summary").Range("A1").Value refers to cell A1 on the Summary sheet in that file. This is safer than using ActiveWorkbook or ActiveSheet, because the active workbook can change if the macro opens another file or the user clicks elsewhere.
You can copy values from the source to the workbook containing the macro, or store them in variables for later processing. If you only need to transfer cell contents, assigning a range’s Value or Value2 is often simpler than copying and pasting, and it avoids carrying formatting unintentionally. Be explicit about which workbook and worksheet supply the data, especially when two files have sheets with identical names.
Close the source when the macro is finished. Passing SaveChanges:=False makes the intention clear: do not save edits made during this session. If the macro changes the source workbook and you want to preserve those changes, read-only is the wrong opening mode; use a controlled writable workflow or save the result to a different file instead.
Choosing related opening options
Several Workbooks.Open options address different issues. They are not interchangeable, so choose according to the task:
ReadOnly:=Truerequests read-only access to the workbook.UpdateLinks:=0prevents updates to external workbook links during opening; it does not cover every external data source.IgnoreReadOnlyRecommended:=Truetells Excel to ignore the workbook’s read-only recommendation prompt.Notify:=Falsedoes not place a locked file on Excel’s notification list; it is not a substitute for requesting read-only access.
A read-only recommendation is a prompt asking users to consider opening a file read-only, not a restriction. Conversely, a file that Excel can only access as read-only may still open that way even when the macro did not request it. Check the resulting workbook’s ReadOnly property when later code depends on whether saving is possible.
Read-only access versus a file lock
Read-only access is not the same thing as a file being locked by another user. If another person has a workbook open for editing, Excel may offer a read-only option, or an application may be unable to obtain the access it requested. Passing ReadOnly:=True is a practical way for a VBA reader to request viewing access without trying to edit the shared source.
Behavior depends on where the file is stored and how it is shared. A local file, a network share, and a workbook stored in OneDrive or SharePoint can have different permission, locking, and coauthoring behavior. In particular, do not assume that a read-only VBA open gives every user a consistent snapshot of a cloud-hosted workbook or prevents other authorized users from editing it. If consistency matters, coordinate access or work from a deliberate copy.
Read-only also does not grant permission to a file that the current Windows account cannot access. If the path is wrong or permissions deny access, the open can fail. A macro should handle that error and report the issue rather than assuming that every failure is caused by another user having the file open.
Common errors and practical fixes
A common failure is an incorrect path, including a misspelled folder, changed filename, or unavailable mapped drive. Confirm the full path and that the file exists and is accessible to the account running Excel. If the path is built from a cell or user input, validate it before calling Workbooks.Open.
Another frequent problem is an incorrect sheet name. Opening the workbook can succeed while a later line such as Worksheets("Summary") fails because the tab has a different name or has been removed. Handle errors around both opening and subsequent sheet references, and consider checking the workbook’s sheet names before trying to read a specific one.
Link-update dialogs, password prompts, protected files, and unavailable network locations can also interrupt automation. Set only the options appropriate to the task, and do not put a real password into a macro that may be shared or exposed. If the workbook must be opened with a password, design a secure process for supplying it and handle an incorrect password as a normal failure case.
When debugging, inspect the exact line that raises the error and check Err.Number and Err.Description before cleanup code changes the error state. Close any workbook the macro successfully opened, even if a later step fails. The sample stores the error description before attempting to close the workbook for this reason.
Read-only is not a security feature
Opening a file read-only helps prevent accidental changes to that source through the current Excel session. It does not encrypt the workbook, hide its contents, or prevent a user from copying data, taking a screenshot, or saving a separate copy. It should not be used as a substitute for file permissions, encryption, or an organizational access policy.
It also does not automatically make a workbook safe to open. A workbook may contain macros, external links, or connections. Read-only access does not itself disable VBA code or make external content harmless. Use files from trusted sources, follow your organization’s macro-security settings, and treat prompts or unexpected content cautiously. For sensitive data, restrict access at the file-storage level rather than relying on an Excel opening option.
Excel for Windows and Mac
The Workbooks.Open method and its ReadOnly argument are available in desktop Excel VBA, including Microsoft 365 for Windows and Excel for Mac. The basic VBA call is the same, but file paths differ: Windows examples commonly use paths such as C:\Reports\Sales.xlsx, while Mac files use Mac-style paths or paths obtained from a Mac file picker. A Windows path pasted into a Mac macro will not identify the same location.
On Windows, Alt+F11 opens the Visual Basic Editor; on a Mac, Option+F11 is the usual equivalent, though some keyboards require Fn as well. Excel for the web does not run VBA macros, so use the desktop application to edit or run this code. Some Windows-specific automation features and controls are not available on Mac, but a basic workbook open and cell read is not dependent on ActiveX.
When to use another approach
If the goal is simply to import data and avoid changing the source, VBA read-only opening is suitable when the workflow already uses macros or requires custom logic. For a repeatable data import with transformation steps, Power Query may be a better fit: it can connect to a workbook and load selected data without writing changes back to the source file. The exact connector and refresh behavior depend on the source location and Excel platform.
If you need multiple users to edit a file together, opening read-only works against that goal. Use the supported sharing and coauthoring features for the file’s storage location, and make sure permissions allow editing. If a macro must update a dataset, consider writing results to a separate output workbook, rather than opening the input read-only and then trying to save changes to it.
Frequently Asked Questions
How do I open an Excel workbook read-only in VBA?
Use Set wb = Workbooks.Open(Filename:=filePath, ReadOnly:=True), with wb declared as a Workbook variable and filePath set to the workbook’s full path.
Can I edit a workbook after opening it read-only?
You may be able to make edits in the open session, but you should not expect to save them over the original file. Use Save As to create a separate copy if you need to retain those changes.
How can I check whether VBA opened the workbook read-only?
After opening it, test wb.ReadOnly. The property reports whether that workbook is currently open as read-only, including cases where Excel’s access conditions caused that state.
Does ReadOnly:=True stop Excel from updating links?
No. Read-only access and link updating are separate settings. Use UpdateLinks:=0 if you want to prevent external workbook links from updating during the open, and manage other data connections separately.
Can I open a workbook read-only if someone else has it open?
Often Excel can open a shared or locked file for reading, but availability depends on the storage system, permissions, and how the other session opened it. Handle errors and check wb.ReadOnly rather than assuming the file will always be accessible.
Does read-only protect confidential workbook data?
No. It is not access control or encryption. Restrict who can access sensitive files using the storage platform’s permissions and appropriate security controls.
Related
- Excel PivotChart: How to Hide Series and Keep Data
- Excel Paste Text Without Text to Columns?
- Excel Paste and Remove Duplicates: Steps and Safety
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Find in Range: Search Cells and Return MatchesTo find a value in an Excel range with VBA, use the range’s Find method and check whether…
- Excel VBA Find Numbers Only: Code, Search Tips, and FixesYes. To find cells that contain real numeric values—not numbers stored as text—loop through the range and check…
- How to Put a Photo in a VBA UserFormTo put a photo in an Excel VBA UserForm, add an Image control, then either set its Picture…
- Excel VBA Worksheet Change Event Not Working? FixesIf an Excel VBA worksheet change event is not working, first check that the Worksheet_Change procedure is in…
- Macro Recorder App: What It Does and How to ChooseA macro recorder app captures a sequence of actions so you can repeat them automatically; in desktop Excel…
- Microsoft Excel VBA Range: Working With Cells and RangesIn Excel VBA, a Range is an object that represents one cell, a rectangular block of cells, or—in…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.