|
有大量txt文本数据,格式是乱的,密密麻麻的排列,想通过excel打开txt文件,使用分隔符使数据格式化,然后在保存txt文件,如何进行批量循环处理呢?我用宏录制的代码如下,E:\测试\ycfortxt下有大量的文件,就是不知道如何循环处理,求各位大神指教!!- Sub test()
- '
- ' test 宏
- '
- '
- ChDir "E:\测试\ycfortxt"
- Workbooks.OpenText Filename:= _
- "E:\测试\ycfortxt\test1.txt", Origin:=936 _
- , StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
- ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
- Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
- , 1), Array(4, 1)), TrailingMinusNumbers:=True
- ActiveWorkbook.Save
- ActiveWindow.Close
- Workbooks.OpenText Filename:= _
- "E:\测试\ycfortxt\test2.txt", Origin:=936 _
- , StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
- ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
- Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
- , 1), Array(4, 1)), TrailingMinusNumbers:=True
- ActiveWorkbook.Save
- ActiveWindow.Close
- Workbooks.OpenText Filename:= _
- "E:\测试\ycfortxt\test3.txt", Origin:=936 _
- , StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
- ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False, Comma:=False, _
- Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3 _
- , 1), Array(4, 1)), TrailingMinusNumbers:=True
- ActiveWorkbook.Save
- ActiveWindow.Close
- End Sub
复制代码
|
|