Changing CSV Files To Excel Files?

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I have several files within a folder all saved as CSV. Is there anyway that I can change them all to Excel files in one go rather than opening them all up and saving as XLS individually?. Thanks.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I am using Excel 2007. I need them saved as .xlsx please.
 
Upvote 0
Try running this - you need to plonk it in a standard module via opening the VBE (Alt+F11) and inserting a module into your chosen workbook (Alt+I+M) and then paste the code in to the module. CLick anywhere in the code and hit F5 to run it. You will be prompted to pick the folder in which to search for the csv files.

Let me know if you need to select only a subset of the csv files within the folder - currently it will do all of them.

Code:
Sub Conv_Files()
Dim strFolder As String
Dim strFile As String
Dim wb As Workbook
Application.DisplayAlerts = False
With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    If .Show = -1 Then strFolder = .SelectedItems(1) Else Exit Sub
End With
strFile = Dir(strFolder & Application.PathSeparator & "*.csv")
If strFile <> "" Then
    Do
        Set wb = Workbooks.Open(strFile)
        wb.SaveAs Left$(wb.Name, InStrRev(wb.Name, ".") - 1), FileFormat:=51
        wb.Close
        strFile = Dir
    Loop Until strFile = ""
Else
    MsgBox "No files found!"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,310
Members
452,906
Latest member
phanmemchatdakenhupviral

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