Hi, I am trying to create a simple custom ribbon through vba with the following code:
public sub Test()
Dim XML as string
XML = "<customUI xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" >"
XML = XML + "<ribbon >"
XML = XML + <tabs >"
XML = XML + "<tab id=""TabMyOwn"" keytip=""E"" label=""My Own Tab""/>"
XML = XML + "</tabs >"
XML = XML + "</ribbon >"
XML = XML + "</customUI >"
ActiveDocument.CustomUI = XML
End Sub
Nothing happens. This is supposed to be some sample XML I got where it creates a single tab. No error messages, nothing. What's wrong? Thank you in advance.
Try saving the active document after running the code, closing it, and and opening it again.
Document custom ribbon is added when Visio opens a document containing it.
Saved and reopened numerous times without success. Bear in mind that the code is in the VBA, thus each time the document is opened, it is loaded and run again.
Quote from: stugol on January 30, 2011, 11:56:38 PM
Saved and reopened numerous times without success. Bear in mind that the code is in the VBA, thus each time the document is opened, it is loaded and run again.
Are you sure you actually ran this code?
Note that you have a typo in it (syntax error), at the line:
XML = XML + <tabs >"
The opening quote around "tabs" is missing. The line should actually be:
XML = XML + "<tabs >"
I mean, to run the code you should do the following steps:
1. Create a new Visio document
2. Open the VBA editor (click Alt+F11, then double-click "ThisDocument")
3. Pate this code (with the typo fixed)
4. Run the code (click "run")
5. Save the drawing (click "save")
6. Close the drawing
7. Open the drawing again. The tab should be shown now
Nikolay, First thank you for answering. I did a typo in this forum but in fact the code was without typos. I even inserted a "debug.assert false" to break and ensure it runs, with no error messages. Nothing happens. Numerous times. Even tried ActiveDocument.UserCustomUI, same thing nothing happens.
Downloaded the sample code for VBA at http://blogs.msdn.com/b/chhopkin/archive/2009/11/20/ribbon-extensibility-for-visio-solutions-in-visio-2010.aspx. Doesn't work either :(
Quote from: stugol on January 31, 2011, 07:42:17 AM
Nikolay, First thank you for answering. I did a typo in this forum but in fact the code was without typos. I even inserted a "debug.assert false" to break and ensure it runs, with no error messages. Nothing happens. Numerous times. Even tried ActiveDocument.UserCustomUI, same thing nothing happens.
Downloaded the sample code for VBA at http://blogs.msdn.com/b/chhopkin/archive/2009/11/20/ribbon-extensibility-for-visio-solutions-in-visio-2010.aspx. Doesn't work either :(
Okay, then I have no idea, sorry. The steps from my post worked just fine for me.
Could it be that Visio is broken on your machine somehow? You could try to repair it by e.g. reinstalling Visio then.
Have you gone through the trust center setings and ensured that the necessary things are enabled (macros, vba projects, etc.)
al
Thanks both. Because Nikolay said it's working for him. I tested it out and it is indeed working. Originally I saved the codes to a stencil and run the code from there, therefore did not save the drawing, so it didn't work. After saving the drawing it works. Thanks.
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: 62 (
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_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_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: 772KB.
Tokens:
post-login.
Cache hits: 7: 0.00097s for 22,301 bytes (
showget modSettings: 0.00039s - 19982 bytes, get known_languages: 0.00013s - 1277 bytes, get board_parents-0: 0.00010s - 2 bytes, get permissions:-1: 0.00011s - 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]