是否有人碰巧知道如何将放置在文件夹中的多个.rtf(富文本文件)转换为R
或SAS
内的PDF?
我将任何应用程序安装到我的电脑上,因此解决方案应该只在我上面提到的两个程序中。
以下是@Reeza慷慨提供的修改代码:
bRecursive = False
sFolder = "C:\PATH"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oFolder = oFSO.GetFolder(sFolder)
ConvertFolder(oFolder)
oWord.Quit
Sub ConvertFolder(oFldr)
For Each oFile In oFldr.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "rtf" Then
Set oDoc = oWord.Documents.Open(oFile.path)
Str = left(oFile,instr(1,oFile,".")-1)
oWord.ActiveDocument.SaveAs Str, 17
oDoc.Close
End If
Next
If bRecursive Then
For Each oSubfolder In oFldr.Subfolders
ConvertFolder oSubfolder
Next
End If
End Sub
上面的.vbs代码有效但我在文件夹中有50个文件,经过大约10个转换后的rtf
做pdf
个文档,它只是保持打开和关闭剩下的文件(似乎)。任何线索?感谢。
答案 0 :(得分:3)
我对此进行了测试,它在我的系统上运行正常。 Windows 7企业版。 VBS脚本保存为.vbs,然后SAS可以使用X命令或%SYSEXEC调用它。
VBS脚本是:
bRecursive = False
sFolder = "C:\_LOCALDATA\temp\_rtf_test\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
Set oFolder = oFSO.GetFolder(sFolder)
ConvertFolder(oFolder)
oWord.Quit
Sub ConvertFolder(oFldr)
For Each oFile In oFldr.Files
If LCase(oFSO.GetExtensionName(oFile.Name)) = "rtf" Then
Set oDoc = oWord.Documents.Open(oFile.path)
Str = left(oFile,instr(1,oFile,".")-1)
oWord.ActiveDocument.SaveAs Str & ".pdf", 17
oDoc.Close
End If
Next
If bRecursive Then
For Each oSubfolder In oFldr.Subfolders
ConvertFolder oSubfolder
Next
End If
End Sub
然后在SAS:
%sysexec "C:\_LOCALdata\SAMPLE.VBS";