Macro for importing a fixed width text file into the activeworkbook
I meant width...if they are then try playing around with this, it's
pretty rough but you'll get the jist of what needs to be done.
Sub ImportFixedWidth(ByVal FileLoc As String, ByVal NumChar As Integer)
Dim x As Integer, TheLine As String
Dim mRow As Integer, mCol As Integer
Open FileLoc For Input Access Read As #1
While Not EOF(1)
Line Input #1, TheLine
mRow = ActiveCell.Row
mCol = ActiveCell.Column
For x = 1 To Len(TheLine) Step NumChar
Cells(mRow, mCol).Value = Mid(TheLine, x, NumChar)
mCol = mCol + 1
Next x
Wend
Close #1
End Sub
HTH
Sandy
Sandy wrote:
Are you're fixed width columns going to all be the exact same
with(meaning number of characters)?
Sandy
Koveras wrote:
I can set up a macro to import a text file just fine, but how can I
write it so that it imports into the active workbook? Pearson's has an
example of importing to an active workbook, but thats limited to
delimited files. How can I modify this to work for a fixed width? any
help is greatly appreciated!
|