Avatar of Sachin Singh
Sachin Singh

asked on 

Convert Csv file to xlsx and delete that csv file

Convert Csv file to xlsx and delete that csv file
Condition=
1)Both the files are located in same place  that is C:\Users\Sholtan\Desktop
2)the name of the csv file may differ
3)My vba code will be placed in Analyser.xlsb
1.csv
Analyser.xlsb
Microsoft OfficeVBAMicrosoft ExcelMicrosoft Applications

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

You can do this manually in seconds using the Get & Transform data" function from the Data Tab of the Ribbon
Place the following code in Analyser.xlsb file.
The code will convert all the csv files into excel files and delete the csv files from the folder where Analyser.xlsb is saved.

Sub ConvertCSVToXLSX()
Dim fso As Object
Dim FolderPath As String
Dim srcFolder As Object
Dim file As Object
Dim wb As Workbook
Dim FileName As String

Application.ScreenUpdating = False

Set fso = CreateObject("Scripting.FileSystemObject")

FolderPath = ThisWorkbook.Path
Set srcFolder = fso.GetFolder(FolderPath)

For Each file In srcFolder.Files
    If fso.GetExtensionName(file) = "csv" Then
        Set wb = Workbooks.Open(file)
        FileName = Left(file.Name, InStr(file.Name, ".") - 1)
        FileName = FileName & ".xlsx"
        wb.SaveAs FolderPath & "\" & FileName, 51
        wb.Close True
        fso.DeleteFile (file)
    End If
Next file
Application.ScreenUpdating = True
End Sub

Open in new window

Avatar of Sachin Singh
Sachin Singh

ASKER

This code is perfect but i missed something
i dont want the  empty rows between the data
Sorry Neeraj Sir  for the same
plz see the sample file i have highlighted  the empty row  i dont want this type of empty row between the data
3.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sachin Singh
Sachin Singh

ASKER

Thnx Neeraj Sir and Roy Cox Sir for ur Great Support
Have a Great Day
You're welcome Sachin!
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo