Visio Guy

Visio Discussions => Programming & Code => Topic started by: stugol on January 29, 2011, 10:02:43 AM

Title: Visio 2010 Ribbon
Post by: stugol on January 29, 2011, 10:02:43 AM
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.
Title: Re: Visio 2010 Ribbon
Post by: Nikolay on January 29, 2011, 11:29:22 AM
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.
Title: Re: Visio 2010 Ribbon
Post by: 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.
Title: Re: Visio 2010 Ribbon
Post by: Nikolay on January 31, 2011, 04:30:56 AM
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
Title: Re: Visio 2010 Ribbon
Post by: 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 :(
Title: Re: Visio 2010 Ribbon
Post by: Nikolay on January 31, 2011, 10:02:46 AM
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.
Title: Re: Visio 2010 Ribbon
Post by: aledlund on January 31, 2011, 01:40:01 PM
Have you gone through the trust center setings and ensured that the necessary things are enabled (macros, vba projects, etc.)
al
Title: Re: Visio 2010 Ribbon
Post by: stugol on February 01, 2011, 01:50:03 PM
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 (show)
Files included: 25 - 925KB. (show)
Memory used: 772KB.
Tokens: post-login.
Cache hits: 7: 0.00097s for 22,301 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]