How put custom image on ribbon with VBA?

C

Christopher King

Greetings,
I am moving a VBA add-in to Excel 2007. Although a button for the add-in
can be installed with a built-in icon, I have not been able to get a custom
icon into the package. A VBA add-in needs to be one file so that it is easy
to install. VBA doesn't have a "resource area" in which to store files, yet,
somehow the custom icon needs to be contained within the add-in. I'm
wondering if anyone knows how to do this. Here's what I've done so far.
My add-in test file, "Testing.xlsm", now has the following structure:
_rels (folder)
.rels
customUI (folder)
customUI.xml
_rels (folder)
customUI.xml.rel
docProps (folder)
Images (folder)
O22minus.ico
xl (folder)
[Content_Types].xml

To create this structure, the following were done: The icon file,
"O22minus.ico", was placed in a folder, "Images". This folder was added to
the add-in test file, "Testing.xlsm". (Add .zip to the file name, open, add
the folder, close, remove .zip.)

The "customUI.xml" file has the following following added to the "Button"
section:
image="icon1"
"icon1" is a relationship ID.

To establich a relationship between the two files, a relatonship was
created. A relationship folder, "_rels" was created in the same folder that
contains "customUI.xml". The relationship file placed in "_rels" is called
"customUI.xml.rel". It contains the following five lines:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<Relationships
xmlns="http://schemas.openxmlformats.org/package/2006/relationships">

<Relationship Id="icon1"
Type="http://schemas.microsoft.com/office/2006/relationships/image"
Target="/Images/O22minus.ico"/>

</Relationships>

As you can see, it provides the relation between "icon1" and "O22minus.ico".

When I run this file I get an error message: "Excel found unreadable
content in Testing.xlsm..." On telling Excel to load the file anyway,
another error message says "An error occurred while loading image with
relatonship ID icon1."
My guess is that something needs to be added to the "[Content Types].xml"
file, telling it what a ".ico" file is.
I know Microsoft is hard at work getting Office 2007 ready for release.
I and probably other VBA add-in programers look forward to documentation
showing how to solve the described problem.

Chris
 
C

Christopher King

A spelling error was fixed: customUI.xml.rel should have been
customUI.xml.rels. That got rid of the first error. Now I just get the "An
error occurred while loading image with relatonship ID icon1." That suggests
the structure of file is OK. Could it be that buttons don't allow a custom
image? Seems unlikely.

Chris
 
P

Patrick Schmid [MVP]

Make your life easier...
Get the Custom UI Editor tool:
http://openxmldeveloper.org/articles/CustomUIeditor.aspx
That tool handles all the relationship stuff and embedding of icons for
you. With it, you can focus on the RibbonX. You prob. want to update the
XSD that ships with the editor. You can get an updated XSD and other
resources from
http://blogs.msdn.com/jensenh/archive/2006/09/15/755336.aspx

Let us know if you are having more luck with the Custom UI Editor. Post
back if you have any questions at all.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 
C

Christopher King

Patrick,
Five minutes work, and my problem was solved. Thanks so much for
pointing me to that tool. (Should anyone care, it looks like the trick is
that the content type in [Content_Types].xml for .ico files is image/.ico;
I'd never have guessed that.)
Chris

Patrick Schmid said:
Make your life easier...
Get the Custom UI Editor tool:
http://openxmldeveloper.org/articles/CustomUIeditor.aspx
That tool handles all the relationship stuff and embedding of icons for
you. With it, you can focus on the RibbonX. You prob. want to update the
XSD that ships with the editor. You can get an updated XSD and other
resources from
http://blogs.msdn.com/jensenh/archive/2006/09/15/755336.aspx

Let us know if you are having more luck with the Custom UI Editor. Post
back if you have any questions at all.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

A spelling error was fixed: customUI.xml.rel should have been
customUI.xml.rels. That got rid of the first error. Now I just get the "An
error occurred while loading image with relatonship ID icon1." That suggests
the structure of file is OK. Could it be that buttons don't allow a custom
image? Seems unlikely.

Chris
 
P

Patrick Schmid [MVP]

You are welcome.
If you are interested in RibbonX, subscribe to my blog :)

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Patrick,
Five minutes work, and my problem was solved. Thanks so much for
pointing me to that tool. (Should anyone care, it looks like the trick is
that the content type in [Content_Types].xml for .ico files is image/.ico;
I'd never have guessed that.)
Chris

Patrick Schmid said:
Make your life easier...
Get the Custom UI Editor tool:
http://openxmldeveloper.org/articles/CustomUIeditor.aspx
That tool handles all the relationship stuff and embedding of icons for
you. With it, you can focus on the RibbonX. You prob. want to update the
XSD that ships with the editor. You can get an updated XSD and other
resources from
http://blogs.msdn.com/jensenh/archive/2006/09/15/755336.aspx

Let us know if you are having more luck with the Custom UI Editor. Post
back if you have any questions at all.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 Beta 2 Technical Refresh (B2TR):
http://pschmid.net/blog/2006/09/18/43
***
Customize Office 2007: http://pschmid.net/office2007/customize
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

A spelling error was fixed: customUI.xml.rel should have been
customUI.xml.rels. That got rid of the first error. Now I just get the "An
error occurred while loading image with relatonship ID icon1." That suggests
the structure of file is OK. Could it be that buttons don't allow a custom
image? Seems unlikely.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top