0

I found code to save a single sheet as CSV. But I am getting error: Run-time error '1004' Cannot access read-only document 'MasterCallOneList.CSV'

How to fix?

The document is actually a new document that does not exist, so I don't know why it would say that the document is read-only.

Application.DisplayAlerts = False Dim strFullName As String strFullName = Application.Path + "\MasterOneCallList.CSV" ThisWorkbook.Sheets("Combined").Copy ActiveWorkbook.SaveAs Filename:=strFullName, FileFormat:=xlCSV, CreateBackup:=True ActiveWorkbook.Close Application.DisplayAlerts = True 
1
  • Just a thought, if the document is a new document, is strFullName = Application.Path + "\MasterOneCallList.CSV"-going to work? Commented Apr 17, 2018 at 16:48

2 Answers 2

4

Could be due to protection levels in the application.path directory.

Have you tried

Application.DisplayAlerts = False Dim strFullName As String strFullName = ThisWorkbook.Path + "\MasterOneCallList.CSV" ThisWorkbook.Sheets("Combined").Copy ActiveWorkbook.SaveAs Filename:=strFullName, FileFormat:=xlCSV, CreateBackup:=True ActiveWorkbook.Close Application.DisplayAlerts = True 
Sign up to request clarification or add additional context in comments.

Comments

0
strFullName = Application.Path + "\MasterOneCallList.CSV" 

This could be the error, the path name would be the ms_office excel folder. Try using an actual folder path string and the code should work. If it does work, you would have to figure a way to get an actual path string.

 Sub Button1_Click() Dim strFullName As String Application.DisplayAlerts = False strFullName = "C:\Users\dmorrison\Downloads\TestKryztof" + "\MasterOneCallList.CSV" ThisWorkbook.Sheets("Combined").Copy ActiveWorkbook.SaveAs Filename:=strFullName, FileFormat:=xlCSV, CreateBackup:=True ActiveWorkbook.Close Application.DisplayAlerts = True End Sub 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.