|
本帖最后由 autumnalRain 于 2017-1-9 14:44 编辑
- Sub test()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set fso = CreateObject("scripting.filesystemobject")
- For Each file In fso.getfolder(ThisWorkbook.Path).Files
- If file.Name Like "*.txt" Then
- Set mytext = fso.opentextfile(file.Path)
- mycontent = mytext.readall
- mytext.Close
- arr = Split(mycontent, vbCrLf)
- Set wb = Workbooks.Add
- wb.Sheets(1).[a1].Resize(UBound(arr, 1)) = arr
- wb.Sheets(1).[a1].CurrentRegion.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
- FieldInfo:=Array(Array(0, 1), Array(5, 1), Array(10, 1), Array(17, 1), Array(23, 1), _
- Array(28, 1), Array(31, 1), Array(36, 1), Array(41, 1), Array(48, 1), Array(50, 1)), _
- TrailingMinusNumbers:=True
- ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "" & Split(file.Name, ".")(0) & ".xlsx"
- ActiveWindow.Close True
- End If
- Next file
- Application.ScreenUpdating =TRUE
- Application.DisplayAlerts =TRUE
- End Sub
复制代码
|
|