我写了一个脚本,它的作用是将文件放入文件夹,然后它会自动将文件转换为制表符分隔的文件。然后它会创建一个名为“输出”的新文件夹。我需要做的是能够将其保存到指定位置。下面是我编写的代码的副本。
Dim saveDirBase
set fso = CreateObject("Scripting.FileSystemObject")
set shell = CreateObject("WScript.Shell")
set objExcel = CreateObject("Excel.Application")
set top = fso.GetFolder(shell.CurrentDirectory)
saveDirBase = top & "\" & "output"
Sub TraverseFolders(path)
set folder = fso.GetFolder(path)
XL2Tab(folder)
For each item in folder.SubFolders
If item.Path <> saveDirBase Then
Call TraverseFolders(item.Path)
End If
Next
set folder = Nothing
End Sub
Sub XL2Tab(folder)
Dim saveDir
set files = folder.Files
If folder.Name <> top.Name Then
saveDir = saveDirBase & "\" & folder.Name
Else
saveDir = saveDirBase
End If
If fso.FolderExists(saveDir) = False Then
fso.CreateFolder(saveDir)
End If
For each file In files
If file.Name <> Wscript.ScriptName Then
objExcel.Application.DisplayAlerts = False
Set objWorkbook = objExcel.Workbooks.open(folder.Path & "\" & file.Name)
objWorkbook.SaveAs saveDir & "\" & file.Name & ".txt", -4158
objWorkbook.close
objExcel.Application.DisplayAlerts = True
End If
Next
End Sub
If fso.FolderExists(saveDirBase) = False Then
fso.CreateFolder(saveDirBase)
End If
Call TraverseFolders(top)