I have a text file which is created daily and placed in the same folder each day. The file path of the text file never changes. For now, let's say the path is : "\MyPath\test.csv\"
I want to create a report in MS Excel 2010 where the user can press a button, the text file is imported into a range, say, Worksheets("Sheet1").Range("A1"), and then analysis is performed upon this imported data.
I have been using VBA with MS Excel for a while now and understand how to create a script which will import data from various databases, etc but I can't seem to get my head around importing text files! All the examples I find online seem to open a dialog box for the user to select the text file, but I don't want my user to be able to do this. I want one specific text file to be imported each time, with no imput from the user. All they have to do is press a button to start the macro.
Does someone have a very simple code which will do the importing for me? Basically, I want a macro to import a chosen text file into Sheet1 cell A1. I also want to manually specify the text delimiter within the code.
Any help/advice would be appreciated.
A couple of assumptions to give you some flexibility in customising this code example. My test data file is shown in the image below i.e. ten variable length records, each field delimited by a comma. The code reads the .csv file one record at a time and puts each record on a separate row. Within each row (i.e. for each record), each field is put into a separate cell. It uses a couple of arrays to achieve this. You can adjust the code to suit your context and there are some comments within, to help. Just add a button to call this macro.