OBJECTIVE : Convert CSV type files in specified Folder into XLSX type files.
Appreciate if anyone can correct the following code based on above subject. For some reason , nothing happens when i run the code. i think the issue probably lies in the while loop; where F8 code is
interrupted after Do While xFile <> " " and exits the Loop . ( i.e., it does not carry out the while - do operations)
Thanks
Joe
Sub CSVintoXLSX()
Dim MyOrgFile As String
Dim OldFileName As String
Dim NewFileName As String
Dim xFile As String
Dim myFolder As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
MyOrgFile = ThisWorkbook.Name
myFolder = "C:\Users\C90224589\Downloads\ABC"
xFile = Dir(myFolder & "\" & "*.csv", vbNormal)
Do While xFile <> ""
Workbooks.Open Filename:=myFolder & "\" & xFile
OldFileName = ActiveWorkbook.FullName
NewFileName = myFolder & "\ " & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) & ".xlsx"
ActiveWorkbook.SaveAs Filename:=NewFileName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
Kill OldFileName
xFile = Dir()
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
MsgBox "macro is completed"
End Sub
Appreciate if anyone can correct the following code based on above subject. For some reason , nothing happens when i run the code. i think the issue probably lies in the while loop; where F8 code is
interrupted after Do While xFile <> " " and exits the Loop . ( i.e., it does not carry out the while - do operations)
Thanks
Joe
Sub CSVintoXLSX()
Dim MyOrgFile As String
Dim OldFileName As String
Dim NewFileName As String
Dim xFile As String
Dim myFolder As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.EnableEvents = False
MyOrgFile = ThisWorkbook.Name
myFolder = "C:\Users\C90224589\Downloads\ABC"
xFile = Dir(myFolder & "\" & "*.csv", vbNormal)
Do While xFile <> ""
Workbooks.Open Filename:=myFolder & "\" & xFile
OldFileName = ActiveWorkbook.FullName
NewFileName = myFolder & "\ " & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) & ".xlsx"
ActiveWorkbook.SaveAs Filename:=NewFileName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
Kill OldFileName
xFile = Dir()
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
MsgBox "macro is completed"
End Sub