Forum Discussion

John_cameron121's avatar
John_cameron121
Copper Contributor
Dec 04, 2022

Changing file name

Hi and thanks in advance. 

I am currently using a macro to import data from a file named

2022-12-04_07-23-20_detail_inbound.csv

it imports data from Column D2 down to 60 and the same on column L


when I receive a new file.

2022-11-29_01-11-10_detail_inbound.csv

it comes back with an error.

 

now I know it’s due to the change of the file name and as the file name I keep receiving changes how can I get my macro to pick up on this or is there another way? 

any help would be appreciated

 

 

 

16 Replies

  • John_cameron121 

    Perhaps the easiest way would be to make sure that the .csv file is the active workbook when you start the macro. That way, you can refer to ActiveWorkbook and ActiveSheet.

    If you need to refer to it later on, assign it to a variable:

        Dim CSVSheet As Worksheet
        Set CSVSheet = ActiveSheet
        ' rest of the code goes here
    • John_cameron121's avatar
      John_cameron121
      Copper Contributor

      HansVogelaar 

       

      Thankyou for your assistance, I can’t seem to get this sorted, any chance you could look at the example above so I can put some code in and trial it, I think I could get it working from there 😊

Resources