How to bulk print Visio files

Started by sunnyimran, December 14, 2018, 01:46:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sunnyimran

Hi there,

I have a collection of visio files .vsd that I want to bulk print without opening each in Visio.
I am using Visio 2016. actually a batch script in visio generates these .vsd files. Each .vsd file has multiple pages in it.

Collection will grow slowly and I need to send to print all files in one go
how can I do that?

I tried a utility Free version for this from here:

Print Conductor 6.2 - Free Version
https://www.print-conductor.com/download
It does support visio 2016 .vsd and .vsdx files
I tried printing .vsdx file that I created myself. that goes fine.
But files generated from batch script in a visio vba project, those are not printing.


any solution?




Paul Herber

I can't see any way to print the VBA-generated files without opening them in Visio.
Why do you want to do this printing without opening Visio?
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

sunnyimran

Quote from: Paul Herber on December 14, 2018, 02:17:57 PM
I can't see any way to print the VBA-generated files without opening them in Visio.
Why do you want to do this printing without opening Visio?

When it is a matter of a couple of files it is OK to open in visio and print individually using print dialog.
But when collection grows to more than 50 or 100 or more files then would you like to open each in visio and click on Print button that much times ?

Paul Herber

If all the files are in one folder then open Windows Explorer, find the files, select the ones to print, right-click and select Print.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Surrogate

Quote from: Paul Herber on December 14, 2018, 03:35:28 PM
If all the files are in one folder then open Windows Explorer, find the files, select the ones to print, right-click and select Print.
I used this way when use Win7 5 years ago, but you can print not more than 15 documents. It generate separate PDF documents !
You need create many separate documents or merge in single file ?

Paul Herber

Quote from: Surrogate on December 14, 2018, 06:12:31 PM
I used this way when use Win7 5 years ago, but you can print not more than 15 documents.
Ah, true. I'd not noticed that those menu items disappear with > 15 files selected.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

sunnyimran

For that much files and a growing collection we definitely need a utility. The utility "Print Conductor" I mentioned in my first post is my tested for PDF, .docx, and many other formats but I never tried printing Visio files from it. It is great utility for bulk printing with many features. Such as dedicating different printers for various collection of files in its queue.

I am using Visio 2016. My Visio script is producing output in .vsd format and in PDF format both. I have to print a huge number of files generated by my script. Script generates PDF's and .vsd both versions of same drawing. I am preferring to print .Vsd to my printers as many dimensions etc. and location of drawing objects is more accurate when printed by Visio files rather than by printing its PDF versions.


The documentation of "Print Conductor" says it does support .vsd and .vsdx for Visio 2013 and beyond. I tested saving some drawings in Visio 2016 as .vsd format and the utility is working on that. Only problem occurs when I print the batch of my script's generated Visio files. i have opened a ticket on "Print Conductor" support. But it doesn't seem their issue.

Q.1 What is the difference in saving a file using Visio VBA as .vsd format and by saving an existing .vsdx drawing deliberately as .vsd using Save as dialog box and selecting .vsd format ?


Q.2 Can Visio VBA generate .vsdx format?

Q.3 If I opt to print my batch as PDF how to remove or minimize accuracy differences in Visio Vs PDF print outs?


Paul Herber

A.1 No difference
A.2 Yes
Just use the standard Save methods in VBA.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

sunnyimran

Quote from: Paul Herber on December 15, 2018, 10:28:57 AM
A.1 No difference
A.2 Yes
Just use the standard Save methods in VBA.

Thanks for answering


I confirmed from Print Conductor support site that it supports following visio formats:
VSD, VSDX          Microsoft Visio Drawing Microsoft                Visio 2003 or newer

VSDM                 Microsoft Visio Macro-Enabled Drawing        Visio 2013 or newer



I am using this line of VBA code in a loop to save each single file in batch automation
           ThisDocument.SaveAsFolderPath&"\Myfilename" & ".vsd"


I tried to use the below line to generate .vsdx but then my script is not generating any files
           ThisDocument.SaveAsFolderPath&"\Myfilename" & ".vsdx"



Q.A Is it possible to save my file as .VSDX using Visio VBA code?
Need to experiment generating .vsdx files instead of .vsd, may be that would work with Paper Conductor utility

I tried saving a .vsdx file manually using save as dialog to .vsd format and Paper-conductor utility works fine on that while the .vsd generated from my script doesn't work in Paper-conductor utility.

Q.B How to check the differences between the two .vsd files, the one manually saved as .vsd and the other generated by my script?

Q.B Am I right in observing the difference in printouts of same drawing printed by visio and saved and printed in PDF ? Does it mean to achieve accurate results one should consider printing Visio formats instead of PDF?



sunnyimran

OK guys here is an update

My script is saved in a visio file and when it runs the batch generate routine, it produces .vsd and PDF files
I opened the generated .vsd file and found that this file also includes the VBA code saved within in itself as was in my source Visio file that runs the batch script.

So removing all VBA code (Module-1 in VBA editor) and making sure not Macros exists in my generated .vsd file solve the problem.

Once I manually removed the VBA code and macros from generated .vsd files, Paper-Conductor utility processes the batch perfectly and sends to printer. Yeeeaaaahh ;D

Now my question is :

Q. How can I save .vsd files using Visio VBA script such that saved .vsd file does not include VBA code Modules or Macros saved in it ?
I am sure there is some way to get it done this way.

Waiting for hints.

Surrogate

You can open document which contain macro first.
After this run macro which create new documend, add some shapes in new document, save as vsd and in pdf.
For example you can store your macro in external stencil (vss-document)

sunnyimran

Quote from: Surrogate on December 15, 2018, 02:36:52 PM
You can open document which contain macro first.
After this run macro which create new documend, add some shapes in new document, save as vsd and in pdf.
For example you can store your macro in external stencil (vss-document)

Thanks for suggestion.
This line of code:
                ThisDocument.SaveAsFolderPath&"\Myfilename" & ".vsd"




Does it save whatever is in the parent visio file (which contains this script to generate files). Am I right?


secondly are there no other Visio VBA commands to save target .vsd's with out VBA code and Macro?


wapperdude

#12
This ought to work...at least the simple test case did on V2019.

I created a Visio file which has a save as macro...generated using macro recorder.  The path and filename are hardcoded in this scenario.  The VBA save as line may be either of the following.  The first provides no macros, the 2nd has macros...should there be any.

    Application.ActiveDocument.SaveAsEx "H:\My Visio\Forum Stuff\DeleteMeVBATest3.vsdx", visSaveAsWS + visSaveAsListInMRU
    Application.ActiveDocument.SaveAsEx "H:\My Visio\Forum Stuff\DeleteMeVBATest3.vsdm", visSaveAsWS + visSaveAsListInMRU

Both the first file drawing window and the VBA window must remain open throughout the process.  Well, actually, I haven't tested all of the scenarios, but this does work. 

Now open / create new file you want to save.  Keep that drawing window active.  Switch to the VBA window and run the macro from there.  It saves the new file, without the "script" macro because that macro is associated with the original file, and the code merely saves the currently active file.

HTH.
Wapperdude
Visio 2019 Pro

sunnyimran

I tried both options in a very crude way. I created a drawing with one page, three basic shapes on this page

Started recording a new Macro, Actions performed were:
         File > SaveAs > another directory path\newfilename.vsdm
Stopped recording the macro

Now my Visio automatically shifted to newly saved file "path\newfilename.vsdm"  during macro recording (undesireable, but let's ignore at this point)
Closed visio

Opened the new file "path\newfilename.vsdm" having macro saved in it

Checked that it has Macro code under Module1 of VBA projct
-----Macro Generated Code------
Sub MacroSaveAs()

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    Dim PageNamesU() As String
    Application.ActiveDocument.ServerPublishOptions.SetPagesToPublish visPublishPageAll, PageNamesU, visLangUniversal
    Dim RecordsetIDs() As Long
    Application.ActiveDocument.ServerPublishOptions.SetRecordsetsToPublish visPublishDataRecordsetAll, RecordsetIDs
    Application.ActiveDocument.SaveAsEx "R:\VisioWorks 16.12.2018\Batch\Drawing1.vsdm", visSaveAsWS

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

End Sub
-----Macro Generated Code------


I then changed this line
       Application.ActiveDocument.SaveAsEx "R:\VisioWorks 16.12.2018\Batch\Drawing1.vsdm", visSaveAsWS

To
      Application.ActiveDocument.SaveAsEx "R:\VisioWorks 16.12.2018\Batch\Drawing1.vsdx", visSaveAsWS
   
Tried to run the Macro, it gave error dialog saying that you can't save this file (with macro) to a non-macro file format. If you continue you will lose macro. OR save it in macro enabled file format.

It was obvious as we are trying to save As a file(having this Macro) to a non-macro format .vsdx

My batch uses these lines in a loop to generate(or SaveAs) the batch


ThisDocument.SaveAs FolderPath & "\Book-" & k & ".vsd"
ThisDocument.Save


So here I did the trick

I copied all Macro code to a stencil and saved it separately this way:
I opened in Visio that drawing having macro. Created a new stencil. Added a new module to stencil in VBA. Copied Macro code to stencil' s VBA Module. Save the stencil in as separate macro enabled stencil. . And DELETED the macro code in module1 from main doc. Save all files. Now main doc does not have any macro code. Stencil has it.

Now I ran the macro code from stencil with this line edited to save as .vsdx:
Application.ActiveDocument.SaveAsEx "R:\VisioWorks 16.12.2018\Batch\Drawing1.vsdx", visSaveAsWS

And it did the job. Newly saved file "R:\VisioWorks 16.12.2018\Batch\Drawing1.vsdx" was saved and had no code in it I confirmed.

In my opinion
Application.ActiveDocument.SaveAs   and   Application.ActiveDocument.SaveAsEx has no major difference. Except the later accepts three additional arguments not of my concern:

Document.SaveAsEx Method
expression. SaveAsEx( _FileName_ , _SaveFlags_ )
expression A variable that represents a Document object.

SaveFlags:
visSaveAsRO              The document is saved as read-only.
visSaveAsWS              The current workspace is saved with the file.
visSaveAsListInMRU     The document is included in the Most Recently Used (MRU) list.

These three flags are not meaningful for my cause of saving macro free doc.

So I think it is not the matter of saving, it is the matter of saving what?
A parent file having VBA code using SaveAS any other file (will also contain same VBA code saved in it)
-OR-
A parent file having NO VBA code using SaveAs any other file (will NOT contain VBA code saved in int)






So let me wind up all my explanation and reach a conclusion
--> I feel, if I can do this below, it will solve my problem of having generated files with no VBA code or Macro in them. That way my Bulk utility will accept it as batch and all will be fine :)

   1- If I can save all my VBA code for batch automation in a separate stencil and run the batch code from there. That way my parent drawing doc would by default be VBA code free, so no matter how many times I SaveAs my parent doc, all saved instances would be code free. (one thing to note is my script produces a batch print button in visio ribbon and runs the code when it is clicked, will just transferring the code from main doc to a separate stencil work fine?? )
   
   2- At each SaveAs during the batch run, Visio Window jumps to the newly saved doc. I want it to keep my parent doc intact. Actually this is the default behaviour in Windows OS. In any office App, when you save an existing doc AS another path/filename or anything using Save AS dialog, new Doc is saved and now the App shows new Doc's name in title bar.

If anyone can hint on above two points my issues will be resolved.

Great thanks to everyone participating