Change shapes of Organisation chart with VBA

Started by Cheg, November 08, 2023, 03:17:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Cheg

Hi,

I'm quite new to Visio and I'm trying to automatize some processes in VBA. I've used VBA before with excel but I find it more difficult to find solutions when I use it for Visio.

I am currently trying to build an organisation chart. My data is organised in an Excel sheet, it imports just fine to visio using the wizard. The default shapes are the ones with the belts and a picture which are not what I need. I want to change them to shapetacular without having to do it it manually. I can remove the picture in VBA by changing the value of the user-defined cell HasPicture to zero.

I cannot figure out how to change the shapes to shapetacular and I'm running out of ideas. I've tried


Visio.Documents.Item("Shapetacular.vsdx").Masters.Item("Executive Shapetacular")


but I get the error Invalid document identifier.
I've tried changing the shape master name to shapetacular but it just changes the name, not the shapes...

shp.Master.Name = "Executive Shapetacular"

Any ideas on how to do this task?

Thanks in advance

Nikolay

#1
Just a crazy idea - you can try to delete all other stencils (or hide them from Visio), leaving only the one you want to be used for the OrgChart diagram ("Shapetacular - Organization Chart Shapes.vssx"), and then run the wizard.
If that doesn't work either, you can rename this "Shapetacular - Organization Chart Shapes.vssx" to whatever the wizard is using by default, thus "fooling" the wizard.

In general, the OrgChart wizard was never meant to be used with VBA. It was built to be used by end-users, manually.
So I doubt you'll find any straightforward way to accomplish that.

Cheg

Very interesting, thank you. I didn't know that about the wizard.

How do I rename the "whatevershape.vssx"? I mean, where do I find the place where I rename it?
Does it mean that if only I will be able to get the expected diagram? That if someone else imports the data using the wizard, it will use the default shape? Or can I save it as a kind of template to be used for this specific purpose?

(sorry, you kindly answered my question and I'm shooting a whole bunch back at you)

Nikolay

For me, the files are:

C:\Program Files (x86)\Microsoft Office\root\Office16\visio content\1033\ORGBLT_U.vssx => "Belt"
C:\Program Files (x86)\Microsoft Office\root\Office16\visio content\1033\ORGTAC_U.vssx => "Shapetacular"

Remember to always make backups :)

wapperdude

It's been years since I used the wizard, so, fuzzy memory.  Some thoughts....

1) the wizard does provide option to choice spectacular?  I guess that's rhetorical.
2) make a simple, dummy org chart using desired shapes.  Use wizard to export to an Excel file.  Close / reopen Visio.  Use wizard to import new Excel file.  Is it correct?  If so, how is it different from your original file?  If not...
3) you ought to be able to do shape replace of Document stencil masters with spectacular shapes.  The update doc stencil masters should flush into shapes on drawing pages.  This ought to be automateable with VBA.
Visio 2019 Pro

Nikolay

#5
The bad news is that renaming stencil doesn't really work. The good news is that changing temple does  :)
The "belt" masters are already "packed" into template file, so renaming stencil is of no use, you need to update the template used by the wizard:

1. Locate file C:\Program Files (x86)\Microsoft Office\root\Office16\Visio Content\1033\ORGWIZ_M.VSTX (or ORGWIZ_U.VSTX, depending if you are using metric or imperial units. I'm assuming metric. May also be different for your visio version)
2. Copy this file to, say, MyDocuments
3. Open that (teamplate) file in Visio. Do not double-click it, use "open" command and then browser for the file. Double click creates new file instead of editing template.
4. Click the "Shapetacular" style set button to update it (this is what it was all for). This will update this setting it in the template used by wizard
5. Save the updated template file back.

6. Rename (backup) the original file C:\Program Files (x86)\Microsoft Office\root\Office16\Visio Content\1033\ORGWIZ_M.VSTX => ORGWIZ_M.VSTX.old
7. Copy your modified file ORGWIZ_M.VSTX from myDocuments to C:\Program Files (x86)\Microsoft Office\root\Office16\Visio Content\1033\

That should do the trick. The next time you run the wizard, it should use the selected "style set".

After giving it a second thought, you actually don't need to overwrite anything.. I.e. steps 6,7 are not required.
You can just create OrgChart diagram based on YOUR modified template (created at the step 5). You just double-click that template, and run the wizard.

Cheg

Thank you so much for your answers! Sorry for a late reply...

I changed the template, it works very well. I would never have thought about this.2