D
dvt
Mr. J. said:I have text files which are loaded to excell.
The text files are always of the same format.
I want to load the file, but always I need to mark the positions of
the current loaded file.
How can I load the file always in a fixed format (can I do a
templette for that ?)
I just did something very similar last week. I recorded a macro and then
modified the code slightly to meet my needs. To record a macro, Tools |
Macro | Record new macro.... Then you perform your typical text loading
function and stop the macro recorder. To edit the macro, Tools | Macro |
Macros | (select the macro) Run.
My macro looks like the following. I added the second line to give a prompt
for a new filename each time I execute the macro. You might like to use
that (or you might not .
Sub open_ascii_file()
DirName = "C:\files\pathname"
Filename = InputBox("Enter a filename")
Workbooks.OpenText Filename:=DirName & Filename, Origin:=xlWindows,
StartRow:= _
9, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(12,
1), Array(25 _
, 1), Array(38, 1), Array(51, 1), Array(64, 1), Array(77, 1),
Array(90, 1), Array(103, 1), _
Array(116, 1), Array(129, 1), Array(142, 1), Array(155, 1),
Array(168, 1), Array(181, 1), _
Array(194, 1), Array(207, 1), Array(220, 1), Array(233, 1),
Array(246, 1), Array(259, 1), _
Array(272, 1), Array(285, 1), Array(298, 1), Array(311, 1),
Array(324, 1), Array(337, 1), _
Array(350, 1))
End Sub
Dave
dvt at psu dot edu