+ Reply to Thread
Results 1 to 15 of 15

Convert multiple txt files in folder to csv

Hybrid View

  1. #1
    Valued Forum Contributor than_gold's Avatar
    Join Date
    10-17-2017
    Location
    Coimbatore India
    MS-Off Ver
    Office 365
    Posts
    646

    Re: Convert multiple txt files in folder to csv

    Try this:

    Dim oFSO, myFolder
    Dim xlCSV
    
    myFolder="C:\your\path\to\excelfiles\"
    
    
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    xlCSV = 6 'Excel CSV format enum
    Call ConvertAllExcelFiles(myFolder)
    Set oFSO = Nothing
    
    Call MsgBox ("Done!")
    
    
    Sub ConvertAllExcelFiles(ByVal oFolder)
    Dim targetF, oFileList, oFile
    Dim oExcel, oWB, oWSH
    
        Set oExcel = CreateObject("Excel.Application")
        oExcel.DisplayAlerts = False
        Set targetF = oFSO.GetFolder(oFolder)
        Set oFileList = targetF.Files
        For Each oFile in oFileList
            If (Right(oFile.Name, 4) = "xlsx") Then
                Set oWB = oExcel.Workbooks.Open(oFile.Path)
                For Each oWSH in oWB.Sheets
                    Call oWSH.SaveAs (oFile.Path & oWSH.Name & ".csv", xlCSV)
                Next
                Set oWSH = Nothing
                Call oWB.Close
                Set oWB = Nothing
            End If
        Next
        Call oExcel.Quit
        Set oExcel = Nothing
    
    End Sub
    Regards,
    Thangavel D

    Appreciate the help? CLICK *

  2. #2
    Registered User
    Join Date
    03-12-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    8

    Re: Convert multiple txt files in folder to csv

    Thanks than_gold for your help, I have got a runtime error at....

    Set targetF = oFSO.GetFolder(oFolder)

    Any ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Automatically Convert Txt files in a folder to Excel
    By tommyfernandez in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-20-2016, 08:01 PM
  2. Convert csv files in folder to xlsm
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-13-2015, 09:49 PM
  3. Replies: 1
    Last Post: 03-12-2013, 04:45 AM
  4. Convert all .txt files to .xls in folder
    By natalie1230 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-19-2011, 03:50 AM
  5. Convert all txt files in Folder to csv
    By nms2130 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2011, 11:14 AM
  6. Open rtf files from a folder and convert them to pdf
    By TANATOS in forum Word Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2009, 01:03 PM
  7. Convert Folder of Workbooks to TXT Files
    By dvent in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-17-2009, 06:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1