I am trying to use the SaveAs method to save a .csv document as a .xls document. However, when I try and designate the folder, it fails.
For example, it will save to some default directory (my documents, which is not where I am ready from) here:
Sub csv()
Workbooks.Open Filename:="directory/tmp.csv"
ActiveWorkbook.SaveAs Filename:="test.xlxs", FileFormat:=51, CreateBackup:=False
End Sub
But this fails:
Sub csv()
Workbooks.Open Filename:="directory/tmp.csv"
ActiveWorkbook.SaveAs Filename:="otherdirectory/test.xlxs", FileFormat:=51, CreateBackup:=False
End Sub
Is there a different way to specify the directory?
Use
FileFormat:=xlCSVThis works for me.
Whenever in doubt, record a macro 🙂
The
FileFormatConstant isxlCSV. Either you can typeFileFormat:=xlCSVor you can use it’s actual value which is 6EDIT
I see that you have edited the question 🙂 Let me go through it again 🙂
What is the exact path that you are specifying? I used
Filename:="C:\Users\Siddharth Rout\Desktop\Book1.xlsx"and it works perfectly.