Excel VBA Run-time Error 70: Permission Denied

VBA & macros · Updated November 20, 2026

Excel VBA Run-time error 70, “Permission denied,” means the code tried to access a file, folder, or resource that Windows or another process would not let it use. Check the exact line that fails, then verify the file path, write permissions, read-only or locked status, and whether another application has the file open; the right fix depends on which operation triggered the error.

What error 70 means in Excel VBA

Error 70 is a VBA runtime error, not a single Excel-specific fault. It commonly appears when a macro tries to create, change, rename, delete, or open a file without sufficient access. It can also occur when a file is already locked in a way that conflicts with the access mode requested by the macro. The error message identifies the broad problem, but the statement that raised it and the file involved provide the useful clues.

For example, a macro that uses Open ... For Output needs to create or replace a file. If the destination is read-only or the current Windows account cannot write to its folder, the operation may fail. A macro trying to open a workbook for exclusive access may also fail if another user or process already has it open. These are different situations, even though both can produce error 70.

Error 70 is also different from a macro-security warning. If Excel blocks a macro because of security settings, the code usually does not begin running. Error 70 occurs after VBA has started and reached an operation that it cannot complete. Enabling macros is therefore not a general solution and may create unnecessary security risk.

Common causes to check first

Start with the resource named on the failing line. A path that looks valid may point to a location where the macro can read but not write, or to a file that has changed since the workbook was last used. Common causes include:

  • Folder permissions: Your Windows account may not have permission to create or modify files in the destination. This can happen in managed work folders, shared locations, and some protected system folders.
  • A read-only file: The file’s read-only attribute, or a read-only copy opened by Excel, can prevent changes. A file being open as read-only is not the same thing as the folder itself being unwritable.
  • A file lock: Another Excel session, a colleague, or a background process may have the file open or temporarily locked. A stale lock can sometimes remain after an application closes unexpectedly.
  • Wrong or unavailable path: The code may refer to a drive letter that is not connected, a renamed folder, or a network location that is currently unreachable. A typo can also send the macro somewhere unexpected.
  • Cloud or synchronization activity: OneDrive, SharePoint, or another sync service may be uploading, downloading, or reconciling a file while the macro tries to replace it. Sync conflicts can make behavior intermittent.
  • Conflicting access mode: VBA may request a type of access that is incompatible with how another process has opened the file. The exact statement and file format matter.

Do not assume that an existing file is the problem. If the macro is creating a new file, the destination folder may be the part it cannot access. Conversely, if it is updating a file, the folder may be writable while that particular file is locked or marked read-only.

Find the exact line and resource

When the error appears, choose Debug if the dialog offers it. The Visual Basic Editor highlights the statement that raised the error. Note the full path and the operation on that line: opening, saving, deleting, renaming, or setting an attribute. If the error occurs only for some workbooks or users, compare their file locations and access rights rather than changing code at random.

If the error dialog does not let you debug, run the macro from the Visual Basic Editor with the cursor inside the procedure and use Run or the F5 key. You can also add a breakpoint by clicking beside a code line, then step through the procedure with F8. These are Windows shortcuts; on Mac, the Visual Basic Editor and shortcut behavior can differ, so use its menus or keyboard-shortcut settings if a key does not match.

Inspect any variable that builds the path. A path can be syntactically valid but point to a different folder than intended. For example, C:\Reports\summary.txt and C:\Report\summary.txt are different locations. If a path is assembled from worksheet cells, check for leading or trailing spaces and confirm that the expected drive or folder is available.

Practical fixes in a safe order

  1. Close competing applications. Close other Excel windows and programs that may be using the target file. If it is on a shared drive, ask whether another person is editing it. Reopen the workbook and retry once the file is available.
  2. Test the destination manually. In File Explorer, navigate to the target folder and try creating a harmless test file. If Windows refuses, the issue is likely folder access or availability, not VBA syntax. Delete the test file afterward.
  3. Check file and folder properties. Right-click the file or folder in File Explorer and choose Properties. Review the read-only setting and, where appropriate, the Security tab to see whether your account has the needed access. On a company device, an administrator may control these permissions.
  4. Use a folder you can write to. For diagnosis, try a location under your user profile, such as Documents, rather than a system folder or restricted network location. If the macro works there, investigate the original destination’s permissions or availability.
  5. Check the path and file state. Confirm the folder exists, the drive is connected, and the file has not been renamed. If Excel opened the workbook read-only, close it and reopen it with appropriate access rather than trying to override the restriction in code.
  6. Retry cloud or network operations after synchronization settles. If the destination is in a synced or shared location, wait for sync to finish and check for a conflict copy. Do not repeatedly rerun a macro that overwrites files until you know which copy is current.

Do not solve a permission problem by running Excel as an administrator unless your organization’s support team specifically instructs you to. Elevated access can give a macro broader privileges than needed and may hide the real issue. It is usually safer to use an approved writable folder or have the folder owner correct access.

Test file-writing code carefully

If the failing statement writes a text file, isolate the operation with a small test in a folder you are allowed to use. This example writes a new test file under the current user’s Documents folder. Change the destination only after confirming the folder exists and is writable. The Output mode replaces the contents if a file with that name already exists, so choose a test filename that you do not need to preserve.

Sub WritePermissionTest()
    Dim fileNumber As Integer
    Dim testPath As String

    ' Use a test file in the current user's Documents folder.
    testPath = Environ$("USERPROFILE") & "\Documents\vba_permission_test.txt"
    fileNumber = FreeFile

    On Error GoTo WriteFailed
    Open testPath For Output As #fileNumber
    Print #fileNumber, "VBA file access test"
    Close #fileNumber

    MsgBox "Test file created: " & testPath
    Exit Sub

WriteFailed:
    ' Close the file if the error occurred after it was opened.
    On Error Resume Next
    Close #fileNumber
    MsgBox "Could not write the test file. Error " & Err.Number & ": " & Err.Description
End Sub

Save a copy of the workbook before running any macro. Macros can change or overwrite files, and their actions cannot be undone with Ctrl+Z. This Windows example uses the USERPROFILE environment variable and a Windows-style path; it is not a cross-platform path recipe for Excel on Mac. Mac file access and path handling differ, and macOS privacy permissions may also affect access to locations such as Documents. Use a Mac-specific path and check macOS privacy settings when working in Excel for Mac.

If this test succeeds but the original macro fails, the original destination or the way it opens the file is the likely issue. If the test also fails, check that Documents exists and is writable, and confirm that a security policy or endpoint-protection tool is not preventing the write.

Why read-only, locks, and sharing are easy to confuse

“Read-only” can describe several different things: a file attribute, Excel opening a workbook without edit access, or a user’s permission on a shared folder. They are not interchangeable. Removing a file’s read-only attribute will not grant permission that Windows or a server has denied. Similarly, saving a different copy may avoid a lock but does not fix the access rules for the original.

Modern Excel coauthoring and network file access can also make a workbook appear available while a particular file operation is not. A macro that edits the workbook currently open in Excel is not equivalent to VBA opening a second copy of the same file through a file handle. Be cautious about macros that use Open on a workbook file or attempt to replace it while Excel still has it open. Save and close the relevant workbook first, or redesign the workflow so it does not compete with Excel’s own open file.

Prevent error 70 in recurring macros

For a macro used repeatedly, make the target location explicit and give users a way to choose an approved folder. Avoid hard-coding a personal drive letter or assuming every user has the same network mapping. Check that a destination folder exists before writing, report the full path in an error message, and handle errors near the file operation so users can tell which file caused the problem.

Also consider what the macro should do when a target file already exists. Overwriting may be intended, but it should be a deliberate choice. Alternatives include asking for confirmation, creating a uniquely named output file, or writing to a temporary file and then moving it once the work is complete. Any replacement strategy still needs suitable permissions and can still fail if another process holds the target.

When an error happens only on a shared computer or for a particular user, collect the exact error line, complete path, whether the file was open elsewhere, and whether the user can create a test file in the destination. That information helps distinguish a code defect from an account or network restriction without granting broader permissions than necessary.

Frequently Asked Questions

How do I fix Run-time error 70 in Excel VBA?
Debug the macro to find the failing statement, then check the target path, file lock, read-only state, and your permission to write to the folder. The right fix depends on whether the code is reading, changing, or creating the resource.

Does error 70 mean macros are disabled?
Usually not. Macro-security blocking normally prevents the code from running; error 70 is raised while running code that attempts an operation it cannot access. Do not lower macro security as a first-line fix.

Why does the macro work on my computer but not someone else’s?
The other user may have different folder permissions, a different path or drive mapping, or a file that is open or synchronized differently. Compare the full destination path and test whether that user can create a file in the destination folder.

Can a read-only workbook cause error 70?
It can, depending on what the macro tries to do. A workbook opened read-only cannot be saved over as though it were editable, but a separate output file may still be possible if its destination folder is writable.

Will running Excel as administrator fix permission denied?
It may change access in some circumstances, but it is not a safe general remedy. Use the correct account and an approved writable location, or ask the folder administrator to review permissions instead of granting Excel unnecessary elevated access.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.