Forum Discussion
Ploughguy
Apr 12, 2021Copper Contributor
Mac: Excel 365 macro's SaveAs CSV gives "Run-time error '1004'" "Cannot access read-only document"
This problem is as old as VBA on Mac OS, it seems, but I cannot find a solution that applies in my case. I have a macro that wants to write a sheet as a VBA script. It fails with error 1004: Can...
temphelp
Feb 09, 2024Copper Contributor
After a lot of research (and failed answers), I came up with a simple solution. You must save the file into the official Office folder on your computer (this is a known working solution mentioned many times on various forums). BUT... you can then use the following command to "move" the file out of this folder to wherever you originally wanted it. For example, I wanted the .csv files to be saved to the desktop. I got the 1004 runtime error all the time. Now, I save to the Office folder as a .csv and then just move it to the desktop via this code. No need to first save it as an .xls as some solutions have shown.
** Please note that your office folder location might be different **
Name "/Users/[Username]/Library/Group Containers/UBF8T346G9.Office/User Content.localized/Startup.localized/Excel/[filename].csv" As "/Users/[Username]/Desktop/[filename].csv"
** Please note that your office folder location might be different **
Name "/Users/[Username]/Library/Group Containers/UBF8T346G9.Office/User Content.localized/Startup.localized/Excel/[filename].csv" As "/Users/[Username]/Desktop/[filename].csv"
pjotar
Sep 22, 2024Copper Contributor
temphelp : great addition/solution!
Additionally I might add that when I move the file, I also rename it to .ics - as I want to save the text as in icalendar File. So the steps are :
1 Check if the VBA runs on a Mac
2 SaveAs csv with UTF8 Format in Office Folder
3 Move the file back, also renaming it at the same time
' Define csv file in office folder
officeFolder = "/Users/xxxx/Library/Group Containers/UBF8T346G9.Office/MacOfficeFiles/Kal2ICScreator_utf8.csv"
If InStr(UCase(Application.OperatingSystem), "MAC") > 0 Then
SaveAs FileName:=officeFolder, FileFormat:=xlCSVUTF8
Name officeFolder As Save_Filepath
End if