Forum Discussion

bullk777's avatar
bullk777
Copper Contributor
Nov 26, 2018

Excel Macros

I am trying to import a text file named 2017_recent.txt using macros into a workbook that already has data in it. The issue that I am facing is that this macros has to work for 2018_recent.txt, 2019_recent.txt, and so on for as many years after that. How do I position my macro that imports all of this data and is not just importing 2017 specifically, so that it can adjust to the next year?

1 Reply

  • you can get the year of a date within macro and unite it with the rest of the text file name to get its complete name for example:

     

    dim TxtFileName as string

    TxtFilneName=Year(now()) &"_recent.txt"