Adding a column with the filename as value to a csv

  • hi,


    I found this code to add a column to a csv with the filename as the value, however when running this code on my Scenario, I am getting "Sub or Function not defined" for the 'Cells' function (line 14). I'm assuming I need to specify the file. (I tried 'fn.Cells', 'x.Cells',) but still no joy. Quite new to VBA, can you help? Thank you!


  • Welcome to the Forum. Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.


    How to use code tags


    Just highlight all of the code and press the <> in the post menu above button to add the code tags.


    Thanks.

  • Cells is part of the Excel object model. Are you running this in Excel?

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Thanks for getting back!


    I am in fact running this in Access. My goal is to add the field to the csv file before importing into an access database. Initially I was looking for a way to do it via VBA during the import step itself, however found this code (and suggestion) to do it beforehand, by using this code. Therefore, is there a way to achieve this by running the VBA in access?


    Thanks.

  • This code is specific to Excel. In my opinion it would probably be simpler to import the CSV into your database and then add the additional column to the table created.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!