以下脚本,只是单纯的转换,不会对文件内容进行处理.TXT编码为UNICODE,应该可以解决乱码问题.
使用方法:在用户设置区,将路径设置好即可.- '==============用户设置区================='
- Dim source,destination
- source="d:\test" '源目录
- destination="e:\test" '目的目录
- '========================================='
-
- '=================函数定义区=============='
- '脚本功能:EXCEL文件另存为TXT'
- Function FilesTree(oFolder,dPath,objExcel)
-
- '处理当前目录文件
- Set oFiles = oFolder.Files
- For Each oFile In oFiles
- exName=LCase(Right(oFile.Name,Len(oFile.Name)-InstrRev(oFile.Name,".")+1))
- baseName=Left(oFile.Name,InstrRev(oFile.Name,".")-1)
- If exName=".xls" Or exName=".xlsx" Then
- set objWorkbook=objExcel.Workbooks.open(oFile.Path)
- objExcel.Workbooks(1).SaveAS dPath&"\"&baseName&".txt",42,true
- objExcel.Workbooks(1).Close,ture
- End If
- Next
-
- '递归处理子目录文件
- Set oSubFolders = oFolder.SubFolders
- For Each oSubFolder In oSubFolders
- FilesTree oSubFolder,dPath,objExcel
- Next
-
- End Function
- '================函数定义区结束================='
-
- '================主程序开始====================='
- Set oFso = CreateObject("Scripting.FileSystemObject")
-
- If oFso.FolderExists(source) And oFso.FolderExists(destination) Then
- set objExcel=CreateObject("Excel.Application")
- Set oFolder = oFso.GetFolder(source)
- objExcel.DisplayAlerts = False
- FilesTree oFolder,destination,objExcel
- objExcel.DisplayAlerts = True
- objExcel.Quit ' 退出
- 'msgbox "处理完成"&vbCrlf&" 即将打开目的目录"
- CreateObject("Wscript.Shell").run destination
- Else
- msgbox "源目录或目的目录不存在"
- End If
复制代码
|