News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Making VBA code work for duplicate (multiple instances) shapes

Started by mmulvenna, May 11, 2008, 07:59:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

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, 05: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



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

Mike

Lars-Erik


mmulvenna

Quote from: Lars-Erik on May 13, 2008, 01:21:14 PM
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
Thanks again. I will give it a shot. If I am understanding this correctly, I will also have to use the additional arguments of the CallThis function as I need a number of references to different "sheets" in the called precedure.

Thanks I will play with it to see if my novice experience can get it working. Appreciate all the suggestions. :)

MIke

mmulvenna

I changed all my runmacro functions to the callthis function.  Luckily I only had to change one action cell in sheet.1 as all other sheets action cell formulas reference the action cell formula in sheet.1

In addition I made changes to the VBA code so it did not reference sheet ids and all is working fine.

Thanks to all for the suggestions ;D

Mike

Browser ID: smf (possibly_robot)
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: 261 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1100KB.
Tokens: post-login.
Cache hits: 13: 0.00225s for 26,750 bytes (show)
Cache misses: 2: (show)
Queries used: 15.

[Show Queries]