Author Topic: Method for updating multiple shapesheets at once?  (Read 6090 times)

0 Members and 1 Guest are viewing this topic.

Budgie

  • Jr. Member
  • **
  • Posts: 23
Method for updating multiple shapesheets at once?
« on: October 27, 2009, 08:02:04 PM »
Guys,
   I want to edit the "Text Transform/TxtWidth" attribute of multiple shapes in their respective shapesheets at the same time.  At present I only seem able to edit each shapes shapesheet one at a time which will take me ages (lots of shapes).  Is there a method/tool for updating multiple shapesheets with the same attributes at once?

cheers Tony

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: Method for updating multiple shapesheets at once?
« Reply #1 on: October 27, 2009, 08:27:02 PM »
Don't know of any tools that will do that.  I think it'll need some VBA code.  Something like this to get you started.  The macro searches thru all of the shapes on the active page.  If the Text Transform section is missing, the code adds it.  (Thanks Visio Guy, I stole that from you!).  It then populates the Transform section, and here is where you can make your changes.

HTH
Wapperdude


Code
Sub TxtTranform()
    Dim shp As Shape

    For Each shp In ThisDocument.Pages(1).Shapes
    ' Add the Text Transform section, if it’s not there:
If Not (shp.RowExists(Visio.VisSectionIndices.visSectionObject, Visio.VisRowIndices.visRowTextXForm, Visio.VisExistsFlags.visExistsAnywhere)) Then
Call shp.AddRow(Visio.VisSectionIndices.visSectionObject, Visio.VisRowIndices.visRowTextXForm, Visio.VisRowTags.visTagDefault)
End If
'Populate the Text Transform cells
shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormWidth).FormulaU = "TextWidth(TheText)"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormPinX).FormulaU = "Width*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormPinY).FormulaU = "Height*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormLocPinX).FormulaU = "TxtWidth*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormLocPinY).FormulaU = "TxtHeight*0.5"
                shp.CellsSRC(visSectionObject, visRowTextXForm, visXFormAngle).FormulaU = "0 deg"
    Next
End Sub
« Last Edit: October 27, 2009, 09:17:07 PM by wapperdude »
Visio 2019 Pro

Budgie

  • Jr. Member
  • **
  • Posts: 23
Re: Method for updating multiple shapesheets at once?
« Reply #2 on: October 27, 2009, 09:46:13 PM »
Thanks Wapperdude,
  I've tried your code but I must be missing something (note: I'm very much a code/VBA newbie).  Maybe you can confirm I've done this right?  I created a new VBA module (even tried creating it as a macro) with the code you provided.  I then run the macro/code but when I check the shapes shapesheets they've still got the old value.

   Appreciate your help

cheers Tony

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3833
  • Ideas Visio-lized into solutions
Re: Method for updating multiple shapesheets at once?
« Reply #3 on: October 27, 2009, 10:27:40 PM »
OK.  I'm assuming that you received no errors as far as the code goes.  So, the steps that I would take would be:
1.  Open up a new drawing.
2.  Go to menu bar > Tools > Macro > Visual Basic Editor (or Alt F11)
3.  That pops up the Visual Basic Editor window, and on the left (I think it's call the project window)  there should be a line item ThisDocument.  Double click that.  That brings up the basic editor section.
4.  Copy and paste the code I provided into this window.
5.  Go back to the regular Visio window and place some shapes.  Either drag / drop basic flow chart shapes or just draw some rectangles, circles, etc.
6.  Check what's in the shapesheet just for reference.  The rect's and circles should not have Text Transform sections.
7.  Back to menu bar > Tools > Macro > ThisDocument.  You should see the TxtTransform macro listed.  Click on it.  It should run very quickly.
8.  Recheck the shapesheets.  They should be changed.

That should do it.

HTH
Wapperdude
Visio 2019 Pro

Budgie

  • Jr. Member
  • **
  • Posts: 23
Re: Method for updating multiple shapesheets at once?
« Reply #4 on: October 27, 2009, 10:58:46 PM »
yep, working now. Thanks heaps.