Hi, I am trying to copy a sheet from existing workbook (.xlsx) and save the sheet as new workbook (.csv):
Set newcsv = Workbooks.Add
ThisWorkbook.Sheets("sheet1").Copy before:=newcsv.Sheets(1)
newcsv.SaveAs filename:="/users/XXX/desktop/"newfolder" & "/" & "newcsv" & ".csv", FileFormat:=xlCSV
ThisWorkbook.Close savechanges:=False
It runs into "Run-time error '1004': Cannot Access read-only document 'newcsv.csv.'
I have tried to debug as below:
Remove "fileformet:=xlcsv" and let it push through, file was successfully saved (however, saved csv would trigger security alert when opening)
Since the code does not save the workbook because savechanges:=False, the workbook would close without save, that being said, the vba code remains same with FileFormat:=xlCSV.
When I re-open the workbook and run macro, it pushes through and asks me whether to overwrite previous saved csv file and I can proceed to save it.
The tricky part is that, it appears that all I have done above make the vba/macro just work fine, UNTIL next system reboot... YES reboot.
When system is restarted, the workbook goes back to starting point, run into run-time error '1004'...
Does anyone have any idea how to fix it?
Thanks.
Bookmarks