测试代码(使用方法:将本程序拷贝到待处理txt文件所在目录,运行即可):- msg="注意:程序运行期间,请不要操作word!" & vbcrlf & vbcrlf
- msg=msg & "使用方法:将本程序拷贝到待处理txt文件所在目录,运行即可!"
-
- msg=msg & vbcrlf & vbcrlf & "开始处理?"
- CH=msgbox(msg,vbokcancel,"Txt2Word")
- if CH<>1 then wscript.quit
-
- on error Resume next
- Const ForReading = 1, ForWriting = 2
- Set FSO = CreateObject("Scripting.FileSystemObject")
- set FF=FSO.getfolder(".")
- set FC=FF.files
-
- set WordApp=CreateObject("word.application")
- WordApp.visible=Visible
- WordApp.Documents.Add
- set MyWord=WordApp.Activedocument
-
- FolderPath=FF.path
- For each fl in FC
- ext=Lcase(fso.GetExtensionName(fl))
- if ext="txt" then
- Set f = fso.OpenTextFile(fl, ForReading)
- FileContent=f.readall
- FileName=split(fl.name,".")
- f.close
- MyWord.Content.text=FileContent
-
- MyWord.SaveAs FolderPath & "\" & FileName(0) & ".doc"
- wscript.sleep 1000
- end if
- Next
- WordApp.quit(0)
-
- msgbox "恭喜你,转换完成!",vbokonly+vbinformation,"Txt2Doc"
- set FC=nothing
- set FF=nothing
- Set FSO=nothing
复制代码
|