Hello everyone,
I was wondering if it is possible to bulk convert CSV to XLSX files while retaining the leading zero? I am currently using a similar code shared by user John_w, and I added an additional line where I convert all of the columns to "TEXT". However, I have noticed that the Macro opens the CSV in Excel (instead of NotePad++, where the leading zero is found), where the leading zeroes are omitted. Hence, when the file is converted to XLSX, the leading zero is never there, to begin with. Is there a way where I can open the file in NotePad when the file is being converted?
Code Shared by User John_W
The line of code I have added:
Thank you so much! I really appreciate any help I could get
I was wondering if it is possible to bulk convert CSV to XLSX files while retaining the leading zero? I am currently using a similar code shared by user John_w, and I added an additional line where I convert all of the columns to "TEXT". However, I have noticed that the Macro opens the CSV in Excel (instead of NotePad++, where the leading zero is found), where the leading zeroes are omitted. Hence, when the file is converted to XLSX, the leading zero is never there, to begin with. Is there a way where I can open the file in NotePad when the file is being converted?
Code Shared by User John_W
VBA Code:
Public Sub Convert_CSVs_To_XLSX()
Dim csvFolder As String
Dim fileName As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Select folder containing CSV files"
.InitialFileName = ActiveWorkbook.Path
If .Show Then
csvFolder = .SelectedItems(1) & "\"
Else
Exit Sub
End If
End With
Application.ScreenUpdating = False
Application.DisplayAlerts = False 'suppress warning message if .xlsx file already exists
fileName = Dir(csvFolder & "*.csv")
Do While fileName <> vbNullString
Workbooks.Open csvFolder & fileName
ActiveWorkbook.SaveAs fileName:=csvFolder & Replace(fileName, ".csv", ".xlsx", Compare:=vbTextCompare), FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close False
fileName = Dir
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "Done"
End Sub
The line of code I have added:
VBA Code:
ActiveSheet.Range(lastRow & ":" lastColumn).NumberFormat = "@"
Thank you so much! I really appreciate any help I could get