Try this. Change the file path and file name pattern to suit.
Sub Convert_CSV_Files()
'Declare Variables
Dim strPath As String, strFile As String, counter As Long
strPath = "C:\Users\...\Analysis\" 'File folder path
'File name: "output*.csv" The asterisk is a wild card
'In this case, all file names start with "output" and end with ".csv"
strFile = Dir$(strPath & "output*.csv") 'This gets the first file name (if any) that matches the patterm.
Do While Len(strFile) 'Loop while the file name is not blank
With Workbooks.Open(strPath & strFile) 'Open the csv file
strFile = Replace(strFile, ".csv", ".xlsx") 'Replace file extension in the file name
.SaveAs strPath & strFile, xlOpenXMLWorkbook 'Save as an .xlsx" file
.Close 'Close the .xlsx file
End With
counter = counter + 1 'Count the files converted
'Get the next csv file name.
'Uses the same pattern as the Dir function above
'Returns a blank string after the last csv file.
strFile = Dir$
Loop 'will stop when no more .csv files to open
MsgBox counter & " file(s) converted. ", vbInformation, "Conversions Complete"
End Sub
Bookmarks