Visio 2010 Ribbon

Started by stugol, January 29, 2011, 10:02:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stugol

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.

Nikolay

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.

stugol

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.

Nikolay

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

stugol

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 :(

Nikolay

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.

aledlund

Have you gone through the trust center setings and ensured that the necessary things are enabled (macros, vba projects, etc.)
al

stugol

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.