Importing text file from current workbook directory
Hi everyone...
I apologize in advance because I know I am asking a simple question. I am VERY new to programming in excel and I looked for hours on the forum before posting this.
I want to import text files (without extensions - eg: matsum, not matsum.txt) into excel from the same folder as where the workbook is located. I recorded a macro and changed only one line. The error message displays as run time error: 1004, excel can't find text file... Marco 1 is the one I tried to change, Marco 2 is the one that was recorded.
Please help, I am so frustrated. THANKS in advanced!!!
Instead of adding the information on the ActiveSheet, can I specify the name of the sheet I want this to add to? If there is a better way, please advise. Right now, I am doing the following:
PHP Code:
Sheets("Info").Select
With ActiveSheet.QueryTables.Add(Connection:=...
In addition, every time I run this macro, it adds a new column next to what is there already. Can I specify the import text to REPLACE/ UPDATE the existing information in the SAME COLUMN "$T$12"?
In addition, every time I run this macro, it adds a new column next to what is there already. Can I specify the import text to REPLACE/ UPDATE the existing information in the SAME COLUMN "$T$12"?
'this starts importing from row 3
.TextFileStartRow = 3
So now I can choose to start importing at a chosen row. Is there an option to skip rows 10-30 for example? Also, can I choose to end import row at 50 for example?
In addition, can I display the name of the file I am importing above the cells? For example, messag is my filename. Can I insert this in the cell above to classify my imported data?
I was wondering also if there is a help/ reference manual for EXCEL VB to figure these things out. I don't find the help in excel very useful. This forum is super helpful but I don't want to keep posting and bother you guys if I don't have to.
So now I can choose to start importing at a chosen row. Is there an option to skip rows 10-30 for example? Also, can I choose to end import row at 50 for example?
From the little I know about Querytables I dont think they have this flexibility.
You may want to look at other methods for reading in text files. Some possibilities are:
FileSystemObject
Line Input #
ADO Recordset using MoveNext
In addition, can I display the name of the file I am importing above the cells? For example, messag is my filename. Can I insert this in the cell above to classify my imported data?
I was wondering also if there is a help/ reference manual for EXCEL VB to figure these things out. I don't find the help in excel very useful. This forum is super helpful but I don't want to keep posting and bother you guys if I don't have to.
Thanks again for helping.
I find it generally ok, half the battle for a beginner is knowing what is available in VBA and finding things.
A useful learning tool is recording macros and stepping through the code with the debugger, setting breakpoints and watches. If you highlight a keyword and press F1 it will display the help topic.
There are lots of people on here who will help you out.
Bookmarks