Saturday, February 6, 2016

Merge any number of CSV files into single file within a second (Vbscript)

Sub Combine_CSV_Files

Dim fLocation, sLocation, dLocation, objShell

fLocation = InputBox("please enter the folder location")

If fLocation=vbNullString then
    MsgBox "folder not selected...", vbOKOnly + vbInformation, "Task Cancelled"
    Wscript.quit
End If

sLocation = fLocation & "\*.csv"
dLocation = fLocation & "\Combined_Data.csv"

Set objShell = CreateObject("WScript.Shell")
objShell.Run "cmd /k Copy """ & sLocation & """ """ & dLocation & """ & exit", False
Set objShell = Nothing

End sub

Call Combine_CSV_Files

*********************************************************************************
Copy the above code and paste into notepad file & save the notepad file with .vbs extension.

' Then click on the saved notepad file.
' it will prompt the folder path where all the CVS files stored.
' copy the folder path and paste into the input box
' all the cvs files has been combined within a second with the file name "Combined_Data.csv

Try this very useful..!

No comments:

Post a Comment

Excel VBA to send email from excel with HTML table in a email body

'' Excel vba script to send email from outlook & email body in HTML table format. ''Write down email body in HTML tags...