Custom Image for Ribbon button

Started by daihashi, August 08, 2014, 11:34:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

daihashi

I'm trying to use getImage, or loadimage, to work but it does not seem to be actually loading the image. The buttons work, and there are captions, but no actual images. Is it not possible to use getImage or loadImage with VBA in visio?

I have created functions for this, but still no luck. There is no problem if I simply use imageMso, but I'd really prefer to use my own icons instead of a generic set. I will need this to be portable with the document, so I cannot do it as a VB.net add-in... it must be in VBA.

Any assistance or insight on this would be greatly appreciated. Thanks!

daihashi

Sorry, I should mention that I've tried this in both Visio 2010 and Visio 2013. Unfortunately I have no other versions of Visio at my disposal to do further version testing.

JuneTheSecond

#2
I hope the job by RSut may be help.
http://visguy.com/vgforum/index.php?topic=4522.0
Best Regards,

Junichi Yoda
http://june.minibird.jp/

daihashi

Thanks June; I did come across that thread, and tried some of the things within the links posted inside of it, but did not have much success. Although I suspect that I may have been making some errors or typos in my XML. I will look through it again and give it another try this afternoon. :)

Nikolay

I think you are not making mistakes in xml, take a look at that thread mentioned.

Unfortunately getting custom images by ID looks broken in Visio ribbon if you do it from a document.
If you are desperate to make it work here is some crazy magic (see the attached diagram)

The source code taken from here and adopted to work with Visio:
http://www.vbaexpress.com/forum/showthread.php?36186-Solved-Dynamic-Custom-Images-in-Ribbons

The code on ribbon load (OnLoad) unpacks images from the .vsdx file then loads them in OnGetImage using gdiplus.

WARNING:
It looks like Visio not only ignores ribbon images embedded in the drawing, but also removes them on saving the diagram
So you may need to add images AFTER you saved the diagram (or keep them not in the diagram)
Anyways, it all looks like a bug, hopefully to be fixed.

daihashi

Many thanks Nikolay.. I just spent the last 2 hours trying to make this work again, convinced that the problem was due to something I did incorrectly. I will look at the file you attached and see how I can get it to fit my own needs. Storing the images outside of the local document is not a problem since the Document_opened will download a stencil file, and then open it... so this may help me work around the issue you described.

Thanks again. :)

daihashi

#6
I just wanted to say thanks again. I'm not sure why the author on vbaexpress wrote his code more complicated than necessary, but they must have needed something more dynamic than my requirements. I've further simplified the code to suit my needs, and it works great! The code on the vbaexpress forum is a little crazy, but I have to admit that it is a very clever way to make custom images work... I wouldn't of thought of doing this on my own.

The only downside is that I had also built a Table of Contents into the ribbon that would refresh everytime a new page was added or renamed, but now the document will only populate that list upon open and not refresh while a user is working within it. The refresh of the Table of contents  was accomplished by Unloading ribbonx and then reloading it (in addition to calling 2 other custom functions I built).

I've only been able to get the method that Nikolay to work by using the document.customUI property, which is great... but also means I have lost the ability to refresh the table of contents drop down list. Oh well.. if having nice icons means that the table of contents in the ribbon is only updated upon document open, then this is minor and a very acceptable trade off IMO. I'd much rather have a professional looking product than use the hideous built in MS Office icon set. :)

Thanks again June and Nikolay. :)

daihashi

#7
looks like I spoke a bit too soon. It seems that the code works pretty close to perfect with Visio 2013, but the custom icons were missing again when I took the same files to a workstation with Visio 2010.

Update: I removed Visio 2010 from my work laptop and installed Visio 2013 instead. I've now confirmed the code executes perfectly for 2013, but 2010 doesn't load the images. It's as if Visio 2010 is not able to properly read the IPicture object that gets created. I may have to just concede to using custom icons for Visio verson 15, and using imagemso for all other detected versions. :(