Move Visio Orgcharts to Powerpoint using VBS

Hi Experts,

I have the task to implement a function in a web application that creates orgcharts in Visio and Powerpoint (Intranet environment).
What I do so far:
In the Web application the user defines some filter critera and clicks on "Create Orgchart"
a vbs script is created that is downloaded by the user and executed on the user's desktop
this vbs-script creates an Excel file with the orgchart data on the user's desktop.
it than creates a Visio file and runs the orgchart-addon in order to build the orgchart.
So far, so good, evething works fine, the users have created many fine orgcharts and everybody is smiling.
Now they want to get these orgcharts into Powerpoint slides as much automated as possible.
I added the following after the orgchart is finished in my vbs-script:
I create a powerpoint object and load a template file
In Visio, I loop all pages
for each page I select all content (Orgchart) and copy it to the clipboard
Then I add a new slide in powerpoint and paste the orgchart into that slide
aftre doing some finetuning (resizing, positioning), the Powerpoint presentation contains as many slides as the visio file has pages and all orgcharts are copied over

And here comes the problem:
when I run the orgchart-wizard in my vbs-script, it starts that addon in visio.
But than the vbs-script moves to the next command even if the orgchart has not finished.
That leads to the following:
The orgchart-wizard not only creates the orgcharts on the specified pages in visio, but it also takes care of formatting them properly: shapes are rezised and positioned so that ithey look fine.
But the vbs-script continues with the Powepoint-part at once, before the formatting is ready so that the orgcharts that are copied over to Powerpoint are ugly :-(
Depending on the selected criteria, the orgchart-wizard takes some seconds or a minute,
If I try to wait some time using WScript.sleep 10000, the orgwiz halts and does not continue the formatting job...

Question: how can I tell the vbs-script to wait until the wizard has finished?
Or: what other method could I use to move the orgcharts over to Powerpoint?

Any idea?
Thanks a lot!

Who is Participating?
Scott HelmersConnect With a Mentor Visio Consultant, Trainer, Author, and DeveloperCommented:
It's been a while since I fiddled with VBS but I vaguely recall two ways to launch external code, one that waits for the launched program to finish and one that doesn't. See bWaitOnReturn in this article for an example of what I'm thinking.

Another choice would be have users run a Visio macro to launch the PPT creation code. I realize that requires them to take two actions instead of one, but by having them trigger execution of the second set of code themselves, you are assured that everything in Visio is exactly the way they want it. One way to make this easy for them is for your first set of code to place a button on the org chart; when they double-click the button, your second set of code could then remove the button (so it doesn't appear in PPT) and create the PPT deck.

BTW, if your use of copy/paste is getting the results you want in PPT, that's great. I've used a different approach -- creating and pasting an image -- as described in this article. It provides a high-fidelity rendering in PPT in cases where copy/paste of Visio shapes doesn't provide the best results.
Lupo09Author Commented:
Hi Scott,

thanks for your reply.

I'm afraid the bWaitOnReturn parameter won't work as I don't start an executable, but a vasio addon:

Set VisApp = CreateObject("Visio.Application")
VisApp.visible = True
Set objAddOn = VisApp.Addons.ItemU("OrgCWiz")
objAddOn.Run ("/S-INIT")
objAddOn.Run ("/S-ARGSTR /FILENAME=H:\Data\... "  -  and a lot of parameters )

objAddOn.Run ("/S-RUN")

than I would have to apply the method to the line

objAddOn.Run ("/S-RUN")

That doesn't work, or do you see a way to apply it to the visio-addon-object?

If I don't find a way to wait for the wizard, I would have to build up the PowerPoint file in a second routine that is triggered by the user after the visio wizard is done (like you proposed).

Your approach on how to create Powerpoint slides of Visio pages also is very interesting and valuable for me!

My approach was to select the shapes on a visio page and copy them to the clipboard and than paste them to the PowerPoint slide using pasteSpecial. Here I let the user either copy the orgchart over as an visio-object or as an image, depending on if he wants to edit the powerpont result or if he wants to hand it over to someone who should not be able to edit it. My code for that is:

pptPres.Slides(iSlideNo).Shapes.PasteSpecial 2
   where 2 = past as OLE Object and 10 =  paste as enhanced metafile

I think I can learn a lot of your Visio-Macros for creating those PowerPoint slides.


If you can think of a way to apply the waiting to the orgchart-wizard-addon, I would very gladly hear of it.

Lupo09Author Commented:

maybe you have an idea on howto use the Visio orgwiz-addon on an opened document.

Using the Standard procedure

    Set VisApp = CreateObject("Visio.Application")
    VisApp.visible = True
    Set objAddOn = VisApp.Addons.ItemU("OrgCWiz")
    objAddOn.Run ("/S-INIT")
    objAddOn.Run ("/S-ARGSTR /FILENAME= . . . and some more Parameters )
    objAddOn.Run ("/S-RUN")

will create a new document and run the wizard there.

Even if I open my document first with something like

   Set docsObj = VisApp.Documents
   Set DocObj = docsObj.Add("c:\myVisioFile.vsd")

the wizard will create a new document.

I would like to run the wizard on the current document so that I can open a document containing some macros (for transfering the pages to PowerPoint)  and then run the wizard there.

(running the wizard manually on an opened document using the GUI (orgchart-tab and "Import") will create the orgcharts within the opened document as I want. So it should be possible using vba / vbs as well, I guess)

Do you have an idea?

Thanks a lot!

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Interesting... I can't find a parameter or technique that will create the org chart in the same document as the code either; it always creates a new document. There may be a way, as you suggest, but I haven't stumbled across it.

Another approach: because the newly created org chart becomes the active document, run the create PPT code immediately after running the orgwiz code, i.e.,
Dim OrgChartDoc as Visio.Document
<<<create org chart>>>
Set OrgChartDoc = ActiveDocument
<<<run PPT code against OrgChartDoc>>>

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.