I am trying to find a fast way to save my xlsx
files as csv
files with the same file-name as the xlsx
file (just in csv
forma
Before saving as csv, get the name of the xls file. You can use the ActiveWorkbook.Name
property. Assuming that file is called something.xls
(and not .xlsx
), try this:
Sub Macro1()
XLSName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
ActiveWorkbook.SaveAs Filename:="C:\Users\Username\Desktop\" & XLSName & ".csv", _
FileFormat:=xlCSV, CreateBackup:=False
End Sub
This pulls the workbook name, cuts off the last 4 characters (".xls") and then runs the Save As command appending ".csv" to that. In case your Excel file has the xlsx
extension, change line 2 to:
XLSName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 5)
Let me know if this works for you.