I am trying to run this cmd script using vba which basically merges all csv files in a directory and then adds the filename of each file into a column at the end.
for /f %a in ('dir /b *.csv') do for /f "tokens=*" %b in (%a) do echo %b,%a >> all.csv
The problem I have is how to run this command in Excel Vba, while changing the default directory before running the above code.
This is because the for /f %a in ('dir /b *.csv') bit just takes your default directory in the cmd window. In the actual cmd window, I can just use the cd command, but no idea how to automate this with vba.
Link to the original post for the code
Any ideas guys?
Thanks
