当前位置 博文首页 > VBS实现DOC转为文本文档的代码

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

    作者:admin 时间:2021-05-12 18:27

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

    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等文件转换为文本文档。
    js