当前位置: 移动技术网 > IT编程>脚本编程>VBScript > VBS实现DOC转为文本文档的代码

VBS实现DOC转为文本文档的代码

2017年12月12日  | 移动技术网IT编程  | 我要评论

安徽萧县车祸,宝矿力水特致癌,嘉定工作

打开记事本输入: 
复制代码 代码如下:

on error resume next 
set args=wscript.arguments 
arg=args(0) 
set w=createobject("word.application") 
set fso=createobject("scripting.filesystemobject") 
set docfile=fso.getfile(arg) 
docpath=docfile.path 
pt=left(docpath,instrrev(docpath,"\")) 
txtpn=pt&left(docfile.name,instrrev(docfile.name,"."))&"txt" 
w.documents.open docpath,,,,,,,,,,,false 
w.documents(docpath).activate 
w.activedocument.saveas txtpn,2 
w.activedocument.close 
w.quit 
set w=nothing 

保存到“c:\windows\doc2txt.vbe”。
记事本编辑
createobject("wscript.shell").regwrite "hkcu\docfile\shell\\转为文本文档\command\","wscript.exe c:\windows\doc2txt.vbe"
记事本编辑
createobject("wscript.shell").regwrite "hkcu\docfile\shell\\转为文本文档\command\","wscript.exe c:\windows\doc2txt.vbe %1"
以上内容保存为*.vbs,运行后,在doc文件上右击,就可以看到“转换为文本文档”项,点击就可以快速转换为文本文档。
以上内容在win2000加word2003下通过测试。
我在试验过程中发现,写入注测表的脚本运行后doc右键有时并没有出现转换菜单,你可以将第二个脚本中的docfile改为*,就是在所有类型文件右键菜单添加转换项。
或者将doc2txt.vbe文件放到"sendto"文件夹,在doc文件上右击选“发送到~doc2txt.vbe”,同样可以转换。
此法同样可以将html,rtf等文件转换为文本文档。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网