There are many file format conversion tools such as Onlineconvertfree for example. The online conversion tools now also support transferring multiple files at the same time, convenient for users to work. When the conversion process is complete and open the folder containing the CSV file, you will see the converted XLXS files. Then click the Run button to run the VBA code. Sub CSVTOXLSX() 'UpdatebyExtendoffice20170814 Dim xFd As FileDialog Dim xSPath As String Dim xCSVFile As String Dim xWsheet As String Application.DisplayAlerts = False Application.StatusBar = True xWsheet = ActiveWorkbook.Name Set xFd = Application.FileDialog(msoFileDialogFolderPicker) xFd.Title = "Select a folder:" If xFd.Show = -1 Then xSPath = xFd.SelectedItems(1) Else Exit Sub End If If Right(xSPath, 1) "" Then xSPath = xSPath + "" xCSVFile = Dir(xSPath & "*.csv") Do While xCSVFile "" Application.StatusBar = "Converting: " & xCSVFile Workbooks.Open Filename:=xSPath & xCSVFile ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".XLXS", vbTextCompare), xlWorkbookDefault ActiveWorkbook.Close Windows(xWsheet).Activate xCSVFile = Dir Loop Application.StatusBar = False Application.DisplayAlerts = True End Sub First, you also open VBA code editor in Excel and enter the code as shown below. In addition to converting CSV to XLS as above we can also convert CSV files to XLSX easily. At the end of the conversion process you open the previously saved CSV file folder.Īs a result, we will see the XLS files as shown below.Ģ. Soon VBA code will run and convert the file. Now display the folder on the computer so we can choose the folder containing the CSV file to move to Excel file, click OK. Sub CSVtoXLS() 'UpdatebyExtendoffice20170814 Dim xFd As FileDialog Dim xSPath As String Dim xCSVFile As String Dim xWsheet As String Application.DisplayAlerts = False Application.StatusBar = True xWsheet = ActiveWorkbook.Name Set xFd = Application.FileDialog(msoFileDialogFolderPicker) xFd.Title = "Select a folder:" If xFd.Show = -1 Then xSPath = xFd.SelectedItems(1) Else Exit Sub End If If Right(xSPath, 1) "" Then xSPath = xSPath + "" xCSVFile = Dir(xSPath & "*.csv") Do While xCSVFile "" Application.StatusBar = "Converting: " & xCSVFile Workbooks.Open Filename:=xSPath & xCSVFile ActiveWorkbook.SaveAs Replace(xSPath & xCSVFile, ".csv", ".xls", vbTextCompare), xlNormal ActiveWorkbook.Close Windows(xWsheet).Activate xCSVFile = Dir Loop Application.StatusBar = False Application.DisplayAlerts = True End Subįinally, click the Run icon in the upper toolbar as shown below to run VBA code. Then we paste the code below into the interface in Excel. Switch to the new user interface, click Insert and then select Module to open the interface to enter the VBA code in Excel. Next, users open Excel and then click on Developer tab and then on Visual Basic.
0 Comments
Leave a Reply. |