Save tabs as separate csv files: Run-time error 1004; cannot access read-only document

ManhattanJM

New Member
Joined
Feb 19, 2022
Messages
6
Office Version
  1. 2016
Platform
  1. MacOS
Hi,

I'm trying to convert tabs into separate csv files, but I'm encountering a Run time error 1004 : Cannot access read-only document with the name of the first tab. Below is my code, please help point me in the right direction. Thank you!
VBA Code:
Sub exportcsv()
Dim ws As Worksheet
Dim path As String

path = ActiveWorkbook.path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
For Each ws In Worksheets
    ws.Activate
    ActiveWorkbook.SaveAs FileName:=path & "_" & ws.Name & ".csv", FileFormat:=xlCSVUTF8, CreateBackup:=False
Next
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Your code works flawlessly for me. Is the path read-only or is the workbook open in read-only mode?
 
Upvote 0
Hi,

I forgot to add that I'm trying to run it on a mac. I'm guessing that's probably the issue...
 
Upvote 0
Try
VBA Code:
Sub exportcsv()
Dim ws As Worksheet
Dim Mypath As String

Mypath = ActiveWorkbook.path & Application.PathSeparator & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
For Each ws In Worksheets
    ws.Activate
    ActiveWorkbook.SaveAs FileName:=Mypath & "_" & ws.Name & ".csv", FileFormat:=xlCSVUTF8, CreateBackup:=False
Next
End Sub
You should avoid using VBA keywords (such as Path) for the names of variables and procedures.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top