Results 1 to 10 of 13

Thread: Csv To Xlsx: Import Export values from Comma delimeted text file to Excel worksheet

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    Csv To Xlsx: Import Export values from Comma delimeted text file to Excel worksheet

    Code:
    Sub CSVToXLS()
        Dim fPath  As String, fPathDONE As String, fCOUNT As Long
        Dim fName  As String, fType    As String
        Dim fAfter As String, NwName    As String
       
        fPath = ThisWorkbook.Path & "\Test\"
        If Right(fPath, 1) <> "\" Then fPath = fPath & "\"
       
        fPathDONE = fPath & "\Converted\"
        MakeFolders fPathDONE
       
        fName = Dir(fPath & "*.CSV")
       
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
       
        Do While Len(fName) > 0
            NwName = Left(fName, InStrRev(fName, ".") - 1)
            Workbooks.Open fPath & fName
            ActiveSheet.Name = NwName
            ActiveWorkbook.SaveAs fPath & NwName & ".xls", FileFormat:=xlNormal
            ActiveWorkbook.Close
           
            Name fPath & fName As fPathDONE & fName
           
            fCOUNT = fCOUNT + 1
            fName = Dir()
        Loop
       
        MsgBox "A Total Of " & fCOUNT & " Files Were Processed"
        Application.ScreenUpdating = True
    End Sub
    
    Function MakeFolders(MyStr As String)
        Dim MyArr  As Variant
        Dim pNum    As Long
        Dim pBuf    As String
       
        On Error Resume Next
       
        MyArr = Split(MyStr, "\")
        pBuf = MyArr(LBound(MyArr)) & "\"
        For pNum = LBound(MyArr) + 1 To UBound(MyArr)
            pBuf = pBuf & MyArr(pNum) & "\"
            MkDir pBuf
        Next pNum
    End Function


    I Have a Macro that works perfectly & I need a little changes in it, Changes are mentioned Below
    1)this macro works only if the file is located in test folder & I want to define the path in the macro, My file alway's be located in C:\Users\WolfieeeStyle\Desktop\Alert..csv & this macro should convert only that file from .csv to .xls & it should delete the .csv file & keep the .xls file to the same location
    And I don't want any msg & any notification stating anything
    So request u to plz look into it
    Last edited by fixer; 06-10-2020 at 01:44 AM.

Similar Threads

  1. Replies: 6
    Last Post: 09-24-2020, 10:36 AM
  2. populate default values in cell of a csv file
    By dhivya.enjoy in forum Excel Help
    Replies: 2
    Last Post: 10-23-2013, 12:59 PM
  3. Replies: 4
    Last Post: 06-20-2013, 04:25 PM
  4. Need VBA code to convert csv to xlsx and vice versa
    By Pravee89 in forum Excel Help
    Replies: 1
    Last Post: 10-13-2012, 11:31 PM
  5. Import text file to an Excel file
    By obed_cruz in forum Excel Help
    Replies: 5
    Last Post: 08-03-2011, 07:58 PM

Tags for this Thread

Posting Permissions

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