Excel VBA runtime error 70, “Permission denied,” means that a VBA operation was refused access to a file, folder, or other protected resource. Find the exact line that fails, then check whether the resource is open, read-only, in a restricted location, or unavailable to your account; the message alone does not identify which cause applies.
What error 70 means
VBA reports error 70 when code tries to perform an operation that the current process is not allowed to perform. In Excel for Microsoft 365 on Windows, it commonly appears during file or folder operations: opening a file for writing, deleting or renaming a file, or creating something in a folder where access is restricted. It can also occur when an operation involving another application or object is denied. The exact meaning depends on the statement that raised the error.
“Permission denied” is not the same as “the file does not exist,” nor does it necessarily mean that your Windows account lacks all access to the file. For example, you might be able to open a workbook in Excel but not overwrite it from a macro because it is read-only or another process has it locked. A network location, synchronization tool, or security policy can also affect access. Treat error 70 as a clue to investigate the failed operation, not as a diagnosis by itself.
The error is a VBA runtime error, not a worksheet formula error. Changing a cell formula or recalculating the workbook will not resolve a file-system permission problem. Likewise, enabling macros only allows code to run; it does not grant the code permission to modify every file or folder.
Start with the exact failing operation
When the error dialog appears, choose Debug if that option is available. The Visual Basic Editor highlights the statement that raised the error. If you are running code from the editor, you can also use Debug > Compile VBAProject to identify certain code problems, although compilation will not reveal runtime access restrictions. The highlighted statement is the best starting point: an error on Kill suggests a different investigation from an error on Open or a call to an external object.
If the macro handles errors and the dialog does not appear, temporarily inspect the error where the handler runs. Record Err.Number, Err.Description, the operation being attempted, and the full path or object name. Do not rely on a generic message such as “could not save”; the path, access mode, and timing often explain the difference between a successful run and a failure.
In Excel, select Developer > Visual Basic to open the editor. In the editor, use View > Immediate Window if you want to inspect values while debugging. On Windows, Alt+F11 opens or switches to the Visual Basic Editor; on Mac, the shortcut can depend on the keyboard’s function-key settings, so the Developer tab is a reliable route. Excel for the web does not run VBA macros; use the desktop application to debug them.
Common file and folder causes
Check the circumstances around the operation, not just the VBA statement. Common causes include:
- The target file is open or locked. Excel, another application, or another user may have the file open in a mode that prevents the requested write, rename, or delete. Close the file everywhere it is in use, then try again. A stale lock or synchronization conflict may require checking the relevant application or service rather than repeatedly rerunning the macro.
- The file or folder is read-only or protected. A read-only file attribute, folder permissions, or an organizational policy may allow reading but block changes. Check the file’s properties and the folder’s Security settings, or ask the administrator if the location is managed.
- The macro writes to a restricted location. Windows system folders and some managed business folders may require permissions the running Excel process does not have. A path under a user-writable folder is a useful comparison. Running Excel as administrator is not a good default fix; it increases the rights of the application and can conceal a path or permission problem.
- The path points somewhere unexpected. A misspelled folder, changed drive letter, unavailable network share, or malformed path can lead to failures. Confirm the complete path at runtime, especially if it is assembled from cell values or environment variables.
- The operation conflicts with the target’s state. Code may try to replace a file that is open, write to a read-only destination, or alter an item that another process is using. Check what already exists at the destination before changing or deleting it.
- A security or synchronization tool blocks the action. Antivirus software, controlled-folder protection, cloud-sync software, and company policies can restrict automated changes. If the problem occurs only in one location, compare it with a permitted folder and consult the relevant administrator rather than disabling security controls.
Do not assume every failed file operation has the same cause. For instance, deleting a file and opening one for output are different requests, and a fix suitable for one can be unsafe for the other.
Diagnose the problem in a safe order
- Identify the precise line. Choose Debug when possible, or add temporary diagnostics around the operation. Note whether the code is opening, writing, deleting, renaming, or creating an item.
- Inspect the full target. Check the resolved path or object name, including the folder, filename, extension, and any values read from worksheet cells. A path that looks right in the code may resolve differently at runtime.
- Check the target manually. In File Explorer, see whether the file exists, is open elsewhere, or is marked read-only. Try the same kind of change using your normal account. A manual failure points toward access or file-state restrictions; a manual success does not rule out a lock or a difference in how the macro opens the file.
- Test in a folder you control. Use a harmless test file in a user-writable location, not a real workbook or a system folder. If the test succeeds but the original destination fails, investigate that destination’s permissions, lock, policy, or availability.
- Check whether the issue is intermittent. A failure that comes and goes may involve a network share, another user, or synchronization. Retrying can be appropriate for a temporary network issue, but do not use repeated retries to overwrite or delete a file without confirming its state.
- Restore the original environment. Once you identify the cause, put the code back into the intended workflow and test on a copy. Avoid leaving temporary error suppression or broad permission changes in the finished macro.
Use a small test instead of changing real files
A simple test can show whether VBA can create a text file in a particular folder. This example appends one line to a file in the current user’s temporary folder. It does not prove that a different folder or workbook is writable; change the path only after selecting a safe test location. Save a copy of the workbook before running any macro: VBA actions cannot be undone with Ctrl+Z.
Sub TestVbaFileAccess()
Dim filePath As String
Dim fileNumber As Integer
Dim fileIsOpen As Boolean
Dim errorNumber As Long
Dim errorText As String
' Use a temporary file rather than a workbook or important document.
filePath = Environ$("TEMP") & "\VbaPermissionTest.txt"
fileNumber = FreeFile
On Error GoTo HandleError
Open filePath For Append As #fileNumber
fileIsOpen = True
Print #fileNumber, "Permission test"
Close #fileNumber
fileIsOpen = False
MsgBox "The temporary file was written.", vbInformation
Exit Sub
HandleError:
errorNumber = Err.Number
errorText = Err.Description
If fileIsOpen Then Close #fileNumber
MsgBox "Error " & errorNumber & ": " & errorText, vbExclamation
End Sub
Append adds a line rather than replacing the existing contents, but this test still creates or modifies a file in the temporary folder. If it succeeds there and fails at the intended destination, focus on the destination’s permissions, availability, or file state. If it fails in the temporary folder too, inspect the error details and whether Windows or security software restricts that location. On Mac, VBA is available in desktop Excel, but Windows environment variables and backslash paths are not portable; use a Mac-appropriate path when adapting the example.
Fixes that match the cause
Once you know what access was denied, make the narrowest appropriate change. Close the file in other applications if it is locked. If the macro should update a read-only file, verify that it is safe to make the file writable and that you have authority to do so. If the destination is restricted, select an approved writable folder or ask the administrator to grant the necessary access. For a missing or incorrect network location, correct the path or restore the connection before running the operation.
When writing VBA, keep the input and output paths explicit and validate them before attempting destructive actions. If code deletes or replaces a file, verify that the target is the intended file and consider preserving a backup. Do not solve error 70 by adding On Error Resume Next around the whole procedure: that statement can hide the failed operation and let later code continue with incomplete or unsafe results. If error handling is needed, handle the specific operation, report the path and error, and stop or recover in a deliberate way.
Why the same macro may work for someone else
Access depends on more than the VBA code. Two users can run the same workbook under different Windows accounts, folder permissions, network connections, or security policies. A file may also be available at one moment and locked at another. Excel’s process context matters too: launching it with different permissions or from a managed location can change what it is allowed to access.
For shared workbooks, check whether the macro assumes a local path that exists only on its author’s computer. A mapped drive letter may not be available to another user or to a process launched under a different account. A UNC network path can make the intended location clearer, but it still requires network access and permission. Avoid embedding credentials or weakening access controls to make a macro run; use an approved location and account configuration.
If you are moving the workbook between Windows and Mac, review file-path construction and any Windows-specific calls. VBA code can be supported in desktop Excel on both platforms, but operating-system APIs, path separators, and access rules are not automatically interchangeable. Excel for the web is different: it cannot execute VBA, so use desktop Excel or consider an appropriate web-based alternative for a workflow that must run in a browser.
Frequently Asked Questions
What causes runtime error 70 in Excel VBA?
It means a VBA operation was denied access. A locked or read-only file, restricted folder, unavailable network location, security policy, or a denied object operation may be responsible. The highlighted line and target are needed to narrow it down.
How do I find which line causes error 70?
Choose Debug in the error dialog to have the Visual Basic Editor highlight the failing statement. If an error handler intercepts the error, temporarily log the error number, description, operation, and full path where the handler runs.
Does error 70 mean the workbook is corrupted?
No. Error 70 describes denied access, not workbook corruption. The macro may be trying to modify a locked file or write to a restricted folder even when the workbook itself is healthy.
Should I run Excel as administrator to fix permission denied?
Usually not as a first step. Elevated access can expose Excel and its macros to broader system permissions and may hide the real issue. First verify the path, lock, file attributes, and account permissions; ask an administrator about managed folders.
Why does the macro work on my computer but not another one?
The other computer may have different folder permissions, drive mappings, network access, file locks, security rules, or operating-system paths. Compare the actual resolved path and account access on both computers rather than assuming the VBA code is the only difference.
Can I fix error 70 with On Error Resume Next?
That can suppress the visible error, but it does not grant access or complete the denied operation. It may also allow later code to run with missing output. Use targeted error handling to report the failed operation, then correct the underlying access or file-state issue.
Related
- Excel Template for a Social Media Calendar
- Excel Job List Template: Track Applications and Follow-Ups
- Excel To-Do List Templates: How to Choose and Use One
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- How to Open the Macro Editor in ExcelIn Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, where you can…
- Excel VBA: Fill a Formula Down to the Last Data RowTo fill a formula in B2 down through the last row that has data in column A, find…
- Excel Macro Error? Common Causes and FixesAn Excel macro error usually means VBA is blocked, the code cannot find an expected workbook, worksheet, or…
- Excel VBA Loop Through a Folder: Practical ExamplesTo loop through files in a folder with Excel VBA, use the Dir function to find a matching…
- Excel VBA: Find the Row Number of a Matching ValueIn Excel VBA, use the Range.Find method to locate a value, then read the matching cell’s .Row property.…
- VBA Sort.Apply: How to Configure and Run Excel SortsSort.Apply is the VBA method that runs a sort after you have configured its range, sort keys, and…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.