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
Sachin SinghAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
You can do this manually in seconds using the Get & Transform data" function from the Data Tab of the Ribbon
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
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

0
Sachin SinghAuthor Commented:
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
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Then try this...
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
Application.DisplayAlerts = 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
        On Error Resume Next
        wb.Sheets(1).Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
        wb.Close True
        fso.DeleteFile (file)
    End If
Next file
Application.ScreenUpdating = True
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sachin SinghAuthor Commented:
Thnx Neeraj Sir and Roy Cox Sir for ur Great Support
Have a Great Day
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Sachin!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.