I receive files on occasion in a fixed width format. I need to import them into Excel but Excel doesn't perfectly pick up the columns. I can do it manually each time with the Text Import Wizard, but I'm wondering if there is a way to create a "text import template" or something similar - since these files are always the same format.
|
feedback
|
|
If you record a macro (Tools - Macro - Record New Macro) while you open the file, you will get the parameters you need to use the OpenText method. Here's an example
The FieldInfo argument is the one you care about. It's an array of 2d arrays. The first element is the column and the second is the data type. This example splits the text file in the following columns: 0, 8, 31, 41, 57, 77, 80, 82, 84, and 86. With that you, you can write a macro to open the text file. See the GetOpenFileName method of the Application object for how to select which file to open. | |||
|
feedback
|
|
If you are fine with some I have used this earlier to do the inverse of what you want -- convert an Excel file to CSV format, Take a look at the examples in the | |||
|
feedback
|