本帖最后由 pcl_test 于 2016-7-24 19:47 编辑
回复 10# pcl_test
我仿照您的代码来转换doc文档,为何提示33行类型不匹配:- Set fso = CreateObject("Scripting.FileSystemObject")
- Set wordApp = CreateObject("Word.application")
- Set ws = CreateObject("WScript.Shell")
- wordApp.visible = true
- srcFolder = "D:\test" '源文件夹
- dstFolder = "E:\Temp" '目标文件夹
- If Not fso.FolderExists(dstFolder) Then fso.CreateFolder(dstFolder)
- Call getSubFiles(srcFolder, "doc")
- wordApp.Quit
- msgbox "Done"
-
- '遍历文件夹查找指定扩展名文件
- Function getSubFiles(path, extension)
- Set Folder = fso.GetFolder(path)
- Set SubFolders = Folder.SubFolders
-
- Set Files = Folder.Files
- For Each File In Files
- If LCase(Right(File.Name, Len(extension))) = LCase(extension) Then
- SaveAsDOC Folder, file
- End If
- Next
-
- For Each SubFolder In SubFolders
- Call getSubFiles(SubFolder.Path, extension)
- Next
-
- Set Folder = nothing
- Set SubFolders = nothing
- End Function
-
- Function SaveAsDOC(folder, file) '增加保留源文件目录结构
- newpath = replace(LCase(Left(folder.Path, Len(srcFolder)))&Mid(folder.Path, Len(srcFolder)+1), LCase(srcFolder), dstFolder)
- If Not fso.FolderExists(newpath) Then ws.run "cmd /c md """&newpath&"", 0
- Set doc = wordApp.Documents.Open(file.Path)
- doc.SaveAs(newpath&"\"&file.Name)
- doc.Close
- End Function
复制代码
|