Hi,
I have this code that is supposed to open excel file, manipulate them, then save the end result as a csv file. It doesn't...
It always tries to replace the original excel sheet (exact name as original file). When I changed:
to
then it kept the original file name (including the .xlsx) and added a .csv to the end.
Where am I going wrong???
AMAS
I have this code that is supposed to open excel file, manipulate them, then save the end result as a csv file. It doesn't...
Code:
Const pathPattern As String = "C:\*.xls*"
fileName = Dir(pathPattern)
Do While fileName <> ""
Set wb = Workbooks.Open(fileName)
With wb.Worksheets(1)
'Do something
End With
wb.SaveAs fileName:=wb.Path & "\" & fileName, FileFormat:=xlCSV, CreateBackup:=False
wb.Close True
fileName = Dir
Loop
It always tries to replace the original excel sheet (exact name as original file). When I changed:
Code:
wb.SaveAs fileName:=wb.Path & "\" & fileName, FileFormat:=xlCSV, CreateBackup:=False
to
Code:
wb.SaveAs fileName:=wb.Path & "\" & fileName & ".csv", FileFormat:=xlCSV, CreateBackup:=False
then it kept the original file name (including the .xlsx) and added a .csv to the end.
Where am I going wrong???
AMAS