I had recorded a Macro to merge 2 txt files from a folder.
Macro Looks like this:
ActiveWorkbook.Queries("test").Delete
ActiveWorkbook.Queries.Add Name:="test", Formula:= _ "let" & Chr(13) & "" & Chr(10) & " Source = Csv.Document(File.Contents(""C:\Users\test\Desktop\folder\test.txt"")
I am planning to copy the excel to a folder that contains the .txt files
How to replace the path C:\Users\test\Desktop\folder\test.txt to use current working folder of worksheet + "\test.txt"?
I am deleting the query in the VBA script to avoid the error "A Query with the name test already exists"
Thisworkbook.Path
to help build the full path to your target file. – Michael Murphy