Macro Correction

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Macro Correction

Post by zyxw1234 »

Code: Select all

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:UsersWolfieeeStyleDesktopAlert..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



https://excelfox.com/forum/showthread.p ... sv-To-Xlsx

User avatar
HansV
Administrator
Posts: 78575
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro Correction

Post by HansV »

Does this do what you want?

Code: Select all

Sub CSVToXLS()
    Dim fPath  As String
    Dim fName  As String
    Dim NwName As String

    fPath = "C:\Users\**I've been banned**\Desktop\"
    fName = "Alert..csv"

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    NwName = Left(fName, InStrRev(fName, ".") - 1)
    Workbooks.Open fPath & fName
    ActiveSheet.Name = NwName
    ActiveWorkbook.SaveAs fPath & NwName & ".xls", FileFormat:=xlExcel8
    ActiveWorkbook.Close

    Kill fPath & fName
       
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
Best wishes,
Hans

zyxw1234
Banned
Posts: 253
Joined: 22 Apr 2020, 17:24

Re: Macro Correction

Post by zyxw1234 »

Awesome HansV Sir, No doubt in it
Thnx Alot Sir for helping me in solving this problem Sir