如何自动分列?

How to divide column automatically?

我有多个 txt 文件(接近 1000 个),我想导入到 excel。我使用文本导入向导然后选择固定宽度,我的问题是如何为我不需要每次调整的每个文件使用相同的格式。

这是示例 link : http://www.fhwa.dot.gov/bridge/nbi/1992/AL92.txt

这是记录格式:http://www.fhwa.dot.gov/bridge/nbi/format.cfm

为了节省您的时间,我根据@RonRosenfeld 的建议为 querytables/import 准备了数组(从上面链接的格式网页),并快速导入了一个文本文件(我记录了). 必须粘贴在这里,因为它对于评论来说太大了。 当然,您必须进行编辑以适应。

With ActiveSheet.QueryTables.Add(Connection:="TEXT;C:\AL92.txt", Destination:=Range("$A"))
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 850
    .TextFileStartRow = 1
    .TextFileParseType = xlFixedWidth
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
    .TextFileFixedColumnWidths = Array(3, 15, 1, 1, 1, 5, 1, 2, 3, 5, 24, 1, 18, 25, 4, 7, 1, 10, 2, 8, 9, 3, 1, 2, 2, 2, 4, 2, 2, 6, 4, 1, 4, 1, 2, 1, 1, 1, 1, 1, 1, 1, 4, 5, 1, 1, 1, 1, 2, 1, 2, 3, 4, 3, 5, 6, 3, 3, 4, 4, 4, 1, 4, 1, 3, 3, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 2, 1, 6, 4, 2, 3, 3, 3, 4, 4, 4, 6, 6, 6, 4, 3, 2, 15, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 2, 1, 1, 1, 1, 6, 4, 4)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
End With