Hi, I came across this script in a old thread which does nearly what i want it to do hoping it can be modified to do what i want but i dont know how the script below will export all .txt files in said directory to excel, I know i can alter the file extension to other file types but is there a way for it to send folder names in said directory to excel, also when dealing with file types is there away of just importing the names without the extension on the end. many thanks for any help. James.
Code:Dim fso, objFolder, obFileList, folderpath, fullpath, xl, i, j folderpath = "C:\Test" Set fso = CreateObject("Scripting.FileSystemObject") Set objFolder = fso.GetFolder(folderpath) Set objFileList = objFolder.Files Set xl = CreateObject("Excel.application") if not fso.folderexists("C:\Forms") then fso.CreateFolder("C:\Forms") end if if not fso.fileexists("c:\Forms\Test.xls") then xl.application.workbooks.add xl.application.save("C:\Forms\Test.xls") xl.application.quit End if xl.Application.Workbooks.Open "C:\Forms\Test.xls" xl.Application.Visible = True set objSheet = xl.ActiveWorkbook.Worksheets(1) i = 1 j = 1 For Each File In objFileList fullpath = folderpath & "\" & file.name if fso.getextensionname(fullpath) = "txt" then objSheet.Cells(i, j).value = file.name i = i + 1 end if Next xl.DisplayAlerts = FALSE objSheet.saveas("C:\Forms\Test.xls") xl.application.quit




Reply With Quote