Code to Modify ShapeSheet Cells of Many Shapes

Started by Visio Guy, May 13, 2008, 10:10:18 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Visio Guy

oompa_l was wondering how to set the Height formula for a bunch of shapes over in this thread: http://visguy.com/vgforum/index.php?topic=47.0

I'll talk about two ways of going about this right now.

Are the shapes all instances of the same master?

If so, then do this:
1. File > Shapes > Show Document Stencil to see the local stencil, which contains masters used in the document
2. Double-click the master icon
3. Edit the formula
   This will change the formula in all the instances in all of the pages in the document -- unless -- you've already overridden formulas in individual shapes.

Write a macro

Like Cyndi Lauper sang, Coders just want to have fun. We can always get more done, more quickly (and cause more trouble) with VBA. So let's have at it:


'// Get a bunch of selected shapes
Dim sel as Visio.Selection
Set sel = Visio.ActiveWindow.Selection

'// 'Do' each shape in the selection:
Dim shp as Visio.Shape
For Each shp in sel

   '// Note: here are several examples that you can
   '//         comment-out and uncomment

   '// Set the value in inches:
   shp.Cells("Width").ResultIU = 2.0

   '//...or set the value in centimeters:
   'shp.Cells("Width").Result(Visio.visUnitCodes.visCentimeters) = 50.8

   '//...or set the formula
   'shp.Cells("Width").Formula = "GUARD(Prop.Row_1)"

   '//...or override a cell that already has a GUARDed formula:
   'shp.Cells("Width").FormulaForce = "GUARD(Prop.Row_1)"

   '// You can get at cells with indices as well:
   'shp.CellsSRC(Visio.VisSectionIndices.visSectionObject, _
   '                  Visio.VisRowIndices.visRowXFormOut, _
   '                  Visio.VisCellIndices.visXFormWidth).Result = 3.0

  '// Put the cursor in a ShapeSheet cell, then hit F1 to get the
  '// Section, Row, Column indices for a cell.

Next shp




For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

oompa_l

where can i go for explanation on implementing macros?

I prefer option 1, but I am still having trouble understanding masters...I would assume tha a change in a master would affect all instances but I have found this not to be the case. Also, when I tried to make a shape from scratch and place in the master a formula that included a formula, in this case "=Prop._VisDM_length_in/50" I was told there was an error in the formula. My guess s that it's because there is no shapesheet data and so it doesnt know what I am referring to. It seems to be a chicken-egg scenario. My is Visio finicky, or what!

oompa_l

i tried to find my way intuitively to making that macro but I got an error:

"Compiler Error
Invalid Outside Procedure"

Visio Guy

The whole bunch of code needs to be wrapped in a sub, ie:

Sub DoStuff

...
...

End Sub
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

oompa_l

#4
woh! it worked...

and...when you have a moment, I am still unsure how to build the formula into the master shape - I was getting an error before. see above.

Browser ID: smf (is_webkit)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 229 (show)
Files included: 34 - 1317KB. (show)
Memory used: 1125KB.
Tokens: post-login.
Cache hits: 13: 0.00226s for 26,582 bytes (show)
Cache misses: 2: (show)
Queries used: 18.

[Show Queries]