Hello,
I'm pretty new at VBA with Visio, and I can't get o understand how Visio's referecing shapes in VBA.
I created a custom shape, made of 2 predefined shapes. This custom shapes thus contains 2 text fields, that I would like to address in VBA.
Let's say I drop onto my page 2 of my custom shapes along with some other shapes. At document opening, I would like to populate 1 text field of my custom shapes, based on the content of the other text field of the custom shape.
How can I, in VBA, only get the ID of my custom shapes, and access to its text fields ?
Hope I'm clear enough in my explanations. I'm using Visio 2003.
Thanks in advance.
aur8l
I guess your custom shape is a grouped shape that contains 2 or more other shapes. So if you have a reference to that shape, you need to look at it's subshapes and than get teir text:
sub test (shp as Shape)
'shp is the reference to the currently somehow selected shape
Dim subshp as Shape
For Each subshp in shp.Shapes '.Shapes is the shape's Shape collection containing all subshapes
MsgBox subshp.Text
Next
End Sub
If your subshapes are grouped shapes, too, then you have ti drill down even more and use above function recursive by adding the line "test subshp"
Thanks.
I figured it out, but the thing is that I want to create a macro which :
- gets a reference to all the custom shapes in the page (so the VSD can evolve without me getting back in the code)
- reads the text form the field 1 in the custom shape, for every custom shape
- refresh the values in the field 2 of the custom shape, for every custom shape
Can I count the number of instances of a certain shape in a page ?
edit : even better, can I get an array of Shape populated only with the instances of my custom shapes on ActivePage ?
edit2 : okay, I can now count the number of custom shapes using ActiveDocument.Masters(name of my custom shape)... Still can't figure out how I can iterate through all those custom shapes to retrieve the value in the field...
The following code iterates through all shapes on the active page:
Sub Iterate()
Dim pg as Page
Dim shp as Shape
Set pg = ActivePage
For each shp in pg.Shapes
If IsCustom(shp) then
CheckText shp
End If
Next shp
End Sub
Function IsCustom(shp as Shape) as Boolean
IsCustom = (shp.Master.Name = "MyMastername")
End Function
Sub CheckText(shp as Shape)
'Code like in my first post
End Sub
Browser ID: smf
(is_webkit)
Templates: 1:
Printpage (default).
Sub templates: 4:
init,
print_above,
main,
print_below.
Language files: 1:
index+Modifications.english (default).
Style sheets: 0:
.
Hooks called: 50 (
showintegrate_autoload, cache_get_data, integrate_pre_load, integrate_load_session, integrate_verify_user, cache_get_data, integrate_user_info, integrate_load_board, cache_get_data, integrate_board_info, cache_get_data, integrate_allowed_to_general, integrate_pre_load_theme, cache_get_data, integrate_allowed_to_general, integrate_simple_actions, integrate_allowed_to_general, integrate_load_theme, integrate_pre_log_stats, cache_get_data, integrate_actions, integrate_pre_parsebbc, integrate_bbc_codes, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_pre_parsebbc, integrate_bbc_print, integrate_post_parsebbc, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general, integrate_menu_buttons, integrate_current_action, integrate_theme_context, integrate_allowed_to_general, integrate_allowed_to_general, integrate_allowed_to_general)
Files included: 25 - 925KB. (
show/home/iw0lkfe3x6cq/public_html/vgforum/index.php, /home/iw0lkfe3x6cq/public_html/vgforum/Settings.php, /home/iw0lkfe3x6cq/public_html/vgforum/cache/db_last_error.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/QueryString.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Auth.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Errors.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Load.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Security.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Compat.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Db-mysql.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApi.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/CacheApiInterface.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Cache/APIs/FileBased.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Subs-Charset.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/Metadata.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/QuickCheck.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Session.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Logging.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Class-BrowserDetect.php, (Current Theme)/languages/index.english.php, (Current Theme)/languages/Modifications.english.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Printpage.php, (Current Theme)/Printpage.template.php, /home/iw0lkfe3x6cq/public_html/vgforum/Sources/Unicode/CaseUpper.php)
Memory used: 771KB.
Tokens:
post-login.
Cache hits: 7: 0.00116s for 22,301 bytes (
showget modSettings: 0.00053s - 19982 bytes, get known_languages: 0.00020s - 1277 bytes, get board_parents-0: 0.00011s - 2 bytes, get permissions:-1: 0.00009s - 50 bytes, get theme_settings-1: 0.00012s - 980 bytes, get log_online-update: 0.00010s - 10 bytes, get menu_buttons--1-english: 0.00001s - 0 bytes)
Cache misses: 1: (
showget menu_buttons--1-english)
Queries used: 9.
[Show Queries]