Here's my attempt:
Option Explicit
Sub Macro2()
'Written by Trebor76
'Convert all *.csv files in a given directory to *.xlsx format
'Visit my website www.excelguru.net.au
Dim objFSO As Object, _
objFSOFolder As Object
Dim strMyPath As String
Dim varFile As Variant
strMyPath = "E:\Excel" 'Put your desired path here.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFSOFolder = objFSO.GetFolder(strMyPath)
Application.ScreenUpdating = False
For Each varFile In objFSOFolder.Files
If StrConv(Mid(varFile, InStrRev(varFile, ".") + 1), vbLowerCase) = "csv" Then 'http://mariaevert.dk/vba/?p=123
If Left(strMyPath, 1) <> "\" Then
ActiveWorkbook.SaveAs Filename:=strMyPath & "\" & ActiveWorkbook.Name & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Else
ActiveWorkbook.SaveAs Filename:=strMyPath & ActiveWorkbook.Name & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End If
ActiveWorkbook.Close
End If
Next varFile
Application.ScreenUpdating = True
Set objFSO = Nothing
Set objFSOFolder = Nothing
MsgBox "Process is now complete"
End Sub
Regards,
Robert
Bookmarks