Reputation: 677
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
Upvotes: 0
Views: 18624
Reputation: 6984
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
Upvotes: 0
Reputation: 66
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
Upvotes: 4