This one is giving me quite a headache as none of the solutions I found online work for me.
I have a folder with a number of excel files which are always named with an alpha-2 country code and a random date (e.g. GB-YYYY-M-D.xlsx). I need to pass the path and the country code as variables to function which opens the file. The dates in filename are not relevant to this and are kind of random, thus I need to replace them with a wildcard. With the example earlier I imagine something like 'path & "\" & countrycode & *.xlsx'. I have learned that this will not work directly with 'Workbooks.open' as it would pass the asterix into the filename instead of it being a wildcard.
Essentially, I need to open a file based on the path and country code provided by variables, perform some actions in it, save and close. Then I need to do the same for the next file and so on. This part I have figured out, however I am unable to get the workbooks open.
A lot of the solutions online discuss the Dir() function in combination with a loop however I don't seem to be able to get it to work as it always returns an empty string. I'm unclear on how to approach this and as you can see I am no VBA expert :D. Any help would be much appreciated.
Dir()is the way to go hereDim f: f = Dir(folderPath & countrycode & "-*.xlsx")assumingfolderpathincludes the terminating \ If you're having problems getting that to work, please update your post with the actual code you're trying.