Pdf 使用VBScript绕过Visio打印确认

Pdf 使用VBScript绕过Visio打印确认,pdf,printing,vbscript,visio,Pdf,Printing,Vbscript,Visio,我需要将数百张visio绘图转换为PDF。我可以右键单击这些,然后按“打印”,但我会为需要打印的每个文档获得一个确认打印框。我曾考虑使用以下代码将文件夹中的所有文档打印到我的默认打印机(PDF),但这也需要确认。有人知道如何修改代码,这样我就不必每次都手动确认了吗 set shApp = CreateObject("shell.application") currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePat

我需要将数百张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
set shApp=CreateObject(“shell.application”)
currentPath=CreateObject(“Scripting.FileSystemObject”).GetAbsolutePathName(“.”)
set shFolder=shApp.NameSpace(currentPath)
set files=shFolder.Items()
对于文件中的每个文件
如果files.name Wscript.ScriptName,则
'msgbox(“打印”和files.name)
files.InvokeVerbEx(“打印”)
如果结束
下一个

您可以直接使用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
set shApp=CreateObject(“shell.application”)
设置visioApp=CreateObject(“Visio.InvisibleApp”)'启动不可见Visio app
currentPath=CreateObject(“Scripting.FileSystemObject”).GetAbsolutePathName(“.”)
set shFolder=shApp.NameSpace(currentPath)
set files=shFolder.Items()
对于文件中的每个文件
如果files.name Wscript.ScriptName,则
'msgbox(“打印”和files.name)
'files.InvokeVerbEx(“打印”)
设置doc=visiapp.Documents.OpenEx(files.path,1+2+128+256)名称,只读+复制+禁用宏+无工作区
doc.ExportAsFixedFormat 1,files.path&“.pdf”,1,0'pdf,文件名,打印机质量,全部打印
结案
如果结束
下一个
visioApp.退出

有关使用Visio 2007或更高版本的用户,请参见

中有关ExportAsFixedFormat的详细信息,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
set shApp=CreateObject(“shell.application”)
设置visioApp=CreateObject(“Visio.InvisibleApp”)'启动不可见Visio app
currentPath=CreateObject(“Scripting.FileSystemObject”).GetAbsolutePathName(“.”)
set shFolder=shApp.NameSpace(currentPath)
set files=shFolder.Items()
对于文件中的每个文件
如果files.name Wscript.ScriptName,则
设置doc=visiapp.documents.open(files.path)
doc.Printer=“\\bprintpdf1\pdf4打印”
文件打印
结案
如果结束
下一个
visioApp.退出

谢谢,但不幸的是,我无法使用该方法,因为我的公司正在使用Visio 2002,而且它不支持该方法。根据你给我的,虽然我设法从应用程序打印到我的默认PDF打印机,工作得很好,不需要我确认。也喜欢看不见的应用程序,所以它不会出现:set doc=visiapp.documents.open(files.path)doc.Print。谢谢,还有,你知道有什么方法可以改变文件名,当它打印成PDF时,就像现在一样,每次我从Visio打印成PDF时,文件都会以Visio-filename.PDF的形式出现在目录中。我有一个单独的脚本,可以循环所有文件删除这个文件,但是如果从一开始就用filename.PDF创建它会更好吗?我想这是默认文件名。(即,打印文件以源文件命名)。也许可以在“pdf打印机”设置中进行配置,但不确定。。除此之外,除了您已经配音的内容,不知道其他内容-只需使用脚本对文件进行后期处理:)