使用VBScript绕过Visio打印确认

时间:2014-11-10 16:13:56

标签: pdf printing vbscript visio

我需要将数百个visio绘图转换为PDF。我可以右键单击这些并按下打印但我得到一个确认打印框,用于打印所需的每个文档。我考虑使用以下代码将文件夹中的所有文档打印到我的默认打印机(PDF),但是这也要求确认。有谁知道如何改变代码所以我不必每次都手动确认?

set shApp = CreateObject("shell.application")
currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") 
set shFolder = shApp.NameSpace( currentPath )
set files = shFolder.Items()
for each files in files

if files.name <> Wscript.ScriptName then
    'msgbox("printing "&files.name)
     files.InvokeVerbEx ("Print") 
end if
next

2 个答案:

答案 0 :(得分:1)

您可以直接使用Visio,并以编程方式“另存为pdf”:

set shApp = CreateObject("shell.application")

Set visioApp = CreateObject("Visio.InvisibleApp") ' start invisible Visio app

currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") 
set shFolder = shApp.NameSpace( currentPath )
set files = shFolder.Items()
for each files in files

if files.name <> Wscript.ScriptName then 
    ' msgbox("printing "&files.name)
    ' files.InvokeVerbEx ("Print") 

    set doc = visioApp.Documents.OpenEx(files.path, 1+2+128+256) ' name, readonly + copy + macro disabled + no workspace
    doc.ExportAsFixedFormat 1, files.path & ".pdf", 1, 0 ' pdf, filename, printer quality, print all
    doc.Close

end if
next

visioApp.Quit

msdn

中查看有关ExportAsFixedFormat的更多信息

答案 1 :(得分:0)

对于使用Visio 2007或更高版本的用户,Nikolay的答案是最佳解决方案。但是,如果像我这样使用2007以下的任何内容,那么以下内容将循环文件并打印每个文件而不要求确认:

set shApp = CreateObject("shell.application")
Set visioApp = CreateObject("Visio.InvisibleApp") ' start invisible Visio app

currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") 
set shFolder = shApp.NameSpace( currentPath )
set files = shFolder.Items()
for each files in files

  if files.name <> Wscript.ScriptName then 

set doc = visioapp.documents.open(files.path)
doc.Printer = "\\bprintpdf1\PDF4Printing"
doc.Print
      doc.Close

   end if
next

visioApp.Quit