Windows 批量打印

用vbs批量打印当前目录及子文件夹WORD文档  

2010-05-21 13:28:27|  分类: 技术|举报|字号 订阅

 
 
       最近搞毕业设计评语,有n多的表格要打印,一个个打印太麻烦,就写了vbs脚本,能打印当前目录下所有
doc文件,并递归打印其子目录,还能对不需要打印的文档进行过滤。
       用记事本新建一个txt文件,拷入如下代码后,另存时选择类型为“所有文件”,文件名为printdoc.vbs,或者其它名字,当扩展名必须为vbs。代码如下
 
filterstr=inputbox("请输入不要打印的文件,用逗号分隔。如2,1表示文件名包含2或者1的不打印,输入*表示打印所有:")
filtered=false
printme=true
if filterstr<>"*" and filterstr<>""  then
   filtered=true
   filterlist=split(filterstr,",")
end if
if filterstr<>"" then
  Set WshShell = WScript.CreateObject("WScript.Shell") 
  printsub(WshShell.CurrentDirectory)
  msgbox "完工啦!"
end if
Sub printsub(byval curdc)
  Set FSO =CreateObject("Scripting.FileSystemObject")
  Set WD = CreateObject("Word.Application")
  wd.visible=false
  Set FD = FSO.GetFolder(curdc)
  Set FN = FD.Files
  For Each F1 In FN
    if filtered then
        printme=true
        for each fl in filterlist
         if Instr(LCase(Left(F1.Name,len(F1.Name)-3)),fl)<>0 then             
             printme=false
         end if
        next
    end if
    If UCase(Right(F1.Name, 3)) = "DOC" and printme Then
        set doc=WD.Documents.Open(FD.Path & "\" & F1.Name)
        doc.PrintOut
        doc.close
        'WD.Documents.Close
        set doc=nothing
    End If
  Next
  wd.visible=true
  WD.Quit
  Set SubFD=FD.SubFolders
  For Each folder in SubFD
    printsub(folder.Path)
  Next
  Set SubFD=nothing
  set fn=nothing
  set fd=nothing
  Set WD = Nothing
  Set FSO = Nothing
End Sub 
        直接双击vbs程序运行,弹出一对话框,如果要打印所有文件,则输入“*”号并确定,如果有不想打印的文件,输入关键字并用逗号分隔,比如“递交,2.1“表示不打印所有文件名中包含”递交“两字或者”2.1”两字的文件。逗号输入用英文方式。程序能打印所有子目录及子子目录,希望大家用的愉快!
 
 
 
 
 

转载于:https://www.cnblogs.com/Dennis-mi/articles/3670238.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值