Sam Hamels
New Member
- Joined
- Mar 20, 2018
- Messages
- 49
I use "Data" -> "From Text" (as shown in the figure below) to import data from many different .txt files into my Excel file.
All these .txt files are in a single folder on my computer. Let's say this folder has the pathname "C:\Users\sam\folder1"
If the data in the .txt files is changed, I can simply click "Refresh All" (also shown in the figure below) to update the data in my Excel file.
Elsewhere on my computer, I have other folders with similar .txt files (same file names but different data values in the files themselves).
I would like to be able to simply make a copy of my current Excel file and adjust all the pathnames referring to the different .txt files, so that they refer to the files in another folder. For example, changing the pathname for a particular textfile (named "textfile1") from "C:\Users\sam\folder1\textfile1.txt" to "C:\Users\sam\folder2\textfile1.txt", and doing this for all the text files that are imported into my Excel file.
Ideally, I would simply have a cell somewhere in my Excel file in which I fill in the portion of the pathname up to the filename itself (in my example the value in this cell would be "C:\Users\sam\folder1" if I want all the text files from this folder to be pulled into my Excel file. I could then very easily adjust the value in this cell to automatically pull the data from a bunch of .txt files in another folder into my Excel file.
If anyone knows how to do this I would be eternally grateful!
I have (almost) no knowledge of VBA code, which I assume will be part of the solution. So if someone can suggest some code I can hopefully just copy-paste it
Thanks!
All these .txt files are in a single folder on my computer. Let's say this folder has the pathname "C:\Users\sam\folder1"
If the data in the .txt files is changed, I can simply click "Refresh All" (also shown in the figure below) to update the data in my Excel file.
Elsewhere on my computer, I have other folders with similar .txt files (same file names but different data values in the files themselves).
I would like to be able to simply make a copy of my current Excel file and adjust all the pathnames referring to the different .txt files, so that they refer to the files in another folder. For example, changing the pathname for a particular textfile (named "textfile1") from "C:\Users\sam\folder1\textfile1.txt" to "C:\Users\sam\folder2\textfile1.txt", and doing this for all the text files that are imported into my Excel file.
Ideally, I would simply have a cell somewhere in my Excel file in which I fill in the portion of the pathname up to the filename itself (in my example the value in this cell would be "C:\Users\sam\folder1" if I want all the text files from this folder to be pulled into my Excel file. I could then very easily adjust the value in this cell to automatically pull the data from a bunch of .txt files in another folder into my Excel file.
If anyone knows how to do this I would be eternally grateful!
I have (almost) no knowledge of VBA code, which I assume will be part of the solution. So if someone can suggest some code I can hopefully just copy-paste it
Thanks!