reading text files

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Reading in text files

Reading in text files

resolvedResolved · Medium Priority · Version 2007

Vlad has attended:
Excel VBA Intro Intermediate course

Reading in text files

Hi Anthony and thanks for the course last week!

As we discussed when you were at Saipem, could you please send me a couple of lines of code I can use for reading in Text files with data and performing the "text to column" function on them (some are space delimited, others comma delimited).

Many thanks!

Vlad

RE: Reading in text files

Hi Vlad, thanks for your query. A couple of lines might be an underestimation. First of all, have a look at the code generated by the macro recorder when you record yourself importing text and using text to columns, it's not that complicated. However, for a more formal walkthrough have a look at this link:

http://www.cpearson.com/excel/ImpText.aspx

There are several different ways to throw text around in Excel and I think using the basic import tool is the way you should go, rather than manipulating the file system object. Whichever way you decide to go, it's an extremely useful thing to be able to automate and you'll find a use for it in many different contexts.

Hope this helps,

Anthony

RE: Reading in text files

Hi Anthony,

Thanks for your answer, I've finally had a chance to try out the code in the link you posted and it does what I wanted. I also tweaked it so that it ignores multiple consecutive separators rather than creating blank cells.

Regards,

Vlad

Wed 28 Dec 2011: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Saving your Excel Spreadsheet as a CSV File

In situations where you need to save your Excel spreadsheet as a CSV file, follow these simple steps.

Click the File tab and click Save As.
Enter a name in the File name field.
Click the drop-down arrow next to the Save as type field to select the file type. Scroll down the list and select CSV (comma delimited) (*.CSV)
Click Save

The data will now be saved to a separate CSV file which can be used in different applications.

View all Excel hints and tips


Server loaded in 0.07 secs.