|
要求很简单,就是将csv文件(其内容就是文本)中的逗号替换成空格,对吗?(后面的文件格式与你的示例不一样)
如果是这样的话把csv文件当文本文件处理就可以了。
- Option Explicit
- Sub BATCHcTXT()
- Dim Pth, FileName, TxtFileName
- Dim oTxt, sTxt, t
- Dim fso, oFile, sFile As Object
- t = Timer
- Set fso = CreateObject("Scripting.FileSystemObject")
- 'Pth = ThisWorkbook.PAth & ""
- Pth = fso.GetFolder(".") & ""
- FileName = Dir(Pth & "*.csv")
- While FileName <> ""
- Set oFile = fso.OpenTextFile(FileName, 1) '读取csv文件
- oTxt = oFile.readall
- oFile.Close
- Set oFile = Nothing
- sTxt = Replace(oTxt, ",", " ") '将逗号替换为空格
- TxtFileName = Replace(LCase(FileName), ".csv", ".txt")
- Set sFile = fso.CreateTextFile(Pth & TxtFileName) '创建txt文件
- sFile.write sTxt '将替换后的内容写进新建的txt文件
- sFile.Close
- Set sFile = Nothing
- FileName = Dir()
- Wend
- Set fso = Nothing
- Application.StatusBar = "用时: " & Timer - t
- End Sub
复制代码
|
|