Visio Discussions > ShapeSheet & Smart Shapes

Making VBA code work for duplicate (multiple instances) shapes

(1/2) > >>

mmulvenna:
I have some VBA code that is executed from the actions section of the shape sheet by using the RUNMACRO function. The code adds some shapes to the page based on the postion of other shapes in the selected group of shapes. It then changes a number of shapesheet values for the shape(s) that were added by the code. Many of the shape sheet formulas reference other shapes in the selected group.

If I make a MASTER from my group of shapes and then add multiple instances of the master will the VBA code work across the instances?

Here is a small sample snipet of the VBA code
.....
.....
      strusercell = "room"
      workstring = vsoShape.AddNamedRow(visSectionUser, strusercell, visTagDefault)

    'Set vsoCell to the cell just created and set its formula.
       Set vsocell = vsoShape.Cells("user.room")
       strformula = "=guard(sheet.1!user.room)"
       vsocell.Formula = strformula
...
...

Will the code work when a second instance of the master is added? i.e will the reference to sheet.1 be changed to the appropiate sheet number for the additional instances added, or am I out in left field?.  ???


Thanks
Mike

mmulvenna:
I haven't tried the "Master" idea yet but since there were no suggestions i will give it a try tomorrow.

Thanks for the views. :-[


Mike

Lars-Erik:
My guess is: No.
Maybe this will get you in the right direction,
This wont work, each time you drag a shape or group to your visio document it will get an unique name. So the first time it might be Sheet.1 the second it will be something else (Sheet.2?) So i think you'll have to try something with CallThis instead of RunMacro
With the CallThis function the shape will be passed to VBA. then you can use that shape to work with instead of using a fixed shape (Sheet.1).

- Lars-Erik

mmulvenna:

--- Quote from: Lars-Erik on May 13, 2008, 12:08:25 AM ---My guess is: No.
Maybe this will get you in the right direction,
This wont work, each time you drag a shape or group to your visio document it will get an unique name. So the first time it might be Sheet.1 the second it will be something else (Sheet.2?) So i think you'll have to try something with CallThis instead of RunMacro
With the CallThis function the shape will be passed to VBA. then you can use that shape to work with instead of using a fixed shape (Sheet.1).

- Lars-Erik



--- End quote ---

Thank you, I will look up the CallThis function and give it a shot.

Mike

Lars-Erik:
Here is an example of the CallThis function:
http://visguy.com/vgforum/index.php?topic=26.0
And here is the SDK interpretation:
http://msdn.microsoft.com/en-us/library/aa212649(office.11).aspx

Navigation

[0] Message Index

[#] Next page

Go to full version