永发信息网

VBS批量打印word和EXCEL

答案:1  悬赏:0  手机版
解决时间 2021-02-12 22:07
以下是批量打印文件夹下的所有的WORD文件 ,谁能帮我修改为批量打印文件夹下的所有EXCEL文件 非常感谢!
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
最佳答案
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("Excel.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)) = "XLS" and printme Then
Set myWork = GetObject(FD.Path & "\" & F1.Name)
Set mySheet = GetObject(FD.Path & "\" & F1.Name).Worksheets(1)
mySheet.PrintOut
myWork.Close saveChanges=False
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
如果你是excel2007以上的,请把代码中的“XLS”改成“LSX”即可。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
口袋妖怪叶绿中的代币盒和百变怪怎么得到?
国家电网电动汽车充电站(福州马尾区湖里路27)
采用沸水消毒蔬菜和水果,浸泡时间应该在( 
有的 股票账户 成本是负数 是什么意思?
我妈给我介绍一个当代莫怀仁给我,但是这个莫
关于机智的俗语,谚语。
ansys特征值屈曲分析后,怎么查看bulkling Val
找一部电影。大概内容只记得 一个单亲爸爸带
众泰t600后座加装电视机
我和男友谈一个月就上床了,这样好吗?
楼面基准地价怎么算
可以用淘米水浇吊兰吗?
金手指投资信息咨询服务有限公司神火大道分公
在武汉哪个区买房性价比最高啊?
吴先生曾经因装修贷款在房管局做抵押登记,当
推荐资讯
i34000双核四线程gtx960m这个配置怎么样?能玩
中国农业银行(环嶝北路88号大嶝小镇)地址有知
简述成功演讲的要领
彪彪奶站在什么地方啊,我要过去处理事情
【蝉晚上会叫吗】“我听到蝉叫的夜晚的声音”
我养的金鱼的眼睛为什么都掉了?怎么办?
台儿庄区气象局地址好找么,我有些事要过去
新星婚纱摄影(罗店镇金龙街113号新星婚纱摄影
将人体的基本组织与功能连线f、上皮组织F产生
停车场(新丰路)(新丰路与永丰大道交叉口东北1
你好,我在连霍高速2625公里处有个违章超速百
名犬坊怎么去啊,我要去那办事
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?