ToniHopkins
ToniHopkins

Reputation: 369

Bypass Visio Print Confirmation using VBScript

I need to convert hundreds of visio drawings to PDF. I can right click these and press print but I get a confirmation print box for every document I need to print. I thought about using the following code to print all documents in the folder to my default printer (PDF) however this also asks for confirmation. Does anyone know how to alter the code so I dont have to manually confirm each time?

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

Upvotes: 0

Views: 421

Answers (2)

ToniHopkins
ToniHopkins

Reputation: 369

For those using Visio 2007 or later then Nikolay's answer is the best solution. However if like me your using anything below 2007 then the following will loop files and print each one without asking for confirmation:

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

Upvotes: 0

Nikolay
Nikolay

Reputation: 12245

You could use Visio directly, and do "save as pdf" programmatically:

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

See more about ExportAsFixedFormat in msdn

Upvotes: 1

Related Questions