Results 1 to 7 of 7

save all csv as xls

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-10-2011
    Location
    Budapest, Hungary
    MS-Off Ver
    Excel 2016
    Posts
    187

    save all csv as xls

    Hello,

    I would like to save all csv files as xls in a directory.
    I have created the attached macro, but the problem is, that in case this macro opens and save the csv files, the separation will be lost, data are separated by semicolon will be merged in one cel.
    I tried to use the opentext method, but I couldn't manage to use it on all files in a directory.

    Could anybody help, how to deal with this problem?


    Thanks

    Sub CsvToXls()
    Dim sfil As String
    Dim sPath As String
    Dim sPath2 As String
    Dim owbk As Workbook
    Dim fName As String
    Dim fnewName As String
    Dim fNameLength As Integer
    Dim newExt As String
    newExt = ".xls"
    
    sPath = ThisWorkbook.Sheets("PARAM").Range("A1")
    sPath2 = ThisWorkbook.Sheets("PARAM").Range("A2")
    
    ChDir sPath
    sfil = Dir("*.csv")
    
    Do While sfil <> ""
          
        Set owbk = Workbooks.Open(sPath & "\" & sfil)
        fName = owbk.Name
        fNameLength = Len(fName) - 4
        fnewName = Left(fName, fNameLength)
        owbk.SaveAs Filename:=sPath2 & "\" & fnewName & newExt, FileFormat:=xlExcel8
           
        owbk.Close False
        
        sfil = Dir
    Loop
    
    End Sub
    Attached Files Attached Files
    Last edited by HarryKlein; 06-05-2011 at 06:49 AM. Reason: test file attached

Thread Information

Users Browsing this Thread

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

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