Convert CSV type files in specified Folder to XLSX type files.

sjohn77

New Member
Joined
Feb 24, 2023
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Does your folder "C:\Users\C90224589\Downloads\ABC" contain at least one .csv file?
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top