Programatically set custom icon to added ribbon button












0















I'm trying to add two icons programmatically to a new ribbon group with VBA. I can add built in icons fine but can't figure out how to use my own files.



TLDR: The code below works if using built in icons with the imageMso attribute but not with custom icons using the image attribute or the getImage callback.



Here is the XML I'm using



<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab id='customTab' label='CP Analyzer' insertAfterMso='TabData'>
<group id='idCPA' label='CP Analyzer'>
<button id='customButton1' label='Select Column' size='large' onAction='SelectColumn' image='imgLabel' />
<button id='customButton2' label='Run Change Point Analyzer' size='large' onAction='RunCP' image='imgFast' />
</group>
</tab>
</tabs>
</ribbon>
</customUI>


I have two .png files (called imgLabel.png and imgFast.png) in the same folder as the add-in containing the above code. From using Microsofts Custom UI Editor to verify the syntax it appears image='myImageName' is correct and works when using the UI Editor, but not when used programmatically in VBA.



How can I reference these images?



Here's the full code, it works by modifying the main Excel.officeUI file:



Sub AddR

Dim hFile As Long
Dim path As String, filename As String, ribbonXML As String, user As String

hFile = FreeFile
user = Environ("Username")
path = "C:Users" & user & "AppDataLocalMicrosoftOffice"
filename = "Excel.officeUI"

ribbonXML = ' the XML above

Open path & filename For Output Access Write As hFile
Print #hFile, ribbonXML
Close hFile

End Sub


I've tried using the getImage callback described here which works fine for a stand-alone file but not as an Add-In which is the important bit for me here.



Specifically, using the Custom UI editor you can set the call back request in a custom UI XML file that gets embedded into the Excel file. Because I need this as an Add-In though I can't do that, since it's only the code that gets included (at least I can't find a way after searching on this all day). Hence my programatic attempt above to change the main Excel.officeUI file (and change it back to its default when the user disables the Add-In).










share|improve this question




















  • 1





    Can you share what you have tried in VBA so far? My initial thought would be to generate an XML file with VBA

    – Zac
    Jan 2 at 11:44











  • @Zac Updated, thanks. I'm modifying the main Excel.officeUI file as I can't find a way to embed XML in an Add-In so that it affects the host instance of Excel while the Add-In is enabled.

    – Absinthe
    Jan 2 at 13:29













  • Have you taken a look at "Custom UI Editor for Microsoft Office"? It's pretty solid tool for creating custom ribbons and allows the use of custom icons.

    – Frank Ball
    Jan 2 at 15:09











  • @FrankBall Yes, it says so in my post :) Thanks anyway.

    – Absinthe
    Jan 2 at 17:37
















0















I'm trying to add two icons programmatically to a new ribbon group with VBA. I can add built in icons fine but can't figure out how to use my own files.



TLDR: The code below works if using built in icons with the imageMso attribute but not with custom icons using the image attribute or the getImage callback.



Here is the XML I'm using



<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab id='customTab' label='CP Analyzer' insertAfterMso='TabData'>
<group id='idCPA' label='CP Analyzer'>
<button id='customButton1' label='Select Column' size='large' onAction='SelectColumn' image='imgLabel' />
<button id='customButton2' label='Run Change Point Analyzer' size='large' onAction='RunCP' image='imgFast' />
</group>
</tab>
</tabs>
</ribbon>
</customUI>


I have two .png files (called imgLabel.png and imgFast.png) in the same folder as the add-in containing the above code. From using Microsofts Custom UI Editor to verify the syntax it appears image='myImageName' is correct and works when using the UI Editor, but not when used programmatically in VBA.



How can I reference these images?



Here's the full code, it works by modifying the main Excel.officeUI file:



Sub AddR

Dim hFile As Long
Dim path As String, filename As String, ribbonXML As String, user As String

hFile = FreeFile
user = Environ("Username")
path = "C:Users" & user & "AppDataLocalMicrosoftOffice"
filename = "Excel.officeUI"

ribbonXML = ' the XML above

Open path & filename For Output Access Write As hFile
Print #hFile, ribbonXML
Close hFile

End Sub


I've tried using the getImage callback described here which works fine for a stand-alone file but not as an Add-In which is the important bit for me here.



Specifically, using the Custom UI editor you can set the call back request in a custom UI XML file that gets embedded into the Excel file. Because I need this as an Add-In though I can't do that, since it's only the code that gets included (at least I can't find a way after searching on this all day). Hence my programatic attempt above to change the main Excel.officeUI file (and change it back to its default when the user disables the Add-In).










share|improve this question




















  • 1





    Can you share what you have tried in VBA so far? My initial thought would be to generate an XML file with VBA

    – Zac
    Jan 2 at 11:44











  • @Zac Updated, thanks. I'm modifying the main Excel.officeUI file as I can't find a way to embed XML in an Add-In so that it affects the host instance of Excel while the Add-In is enabled.

    – Absinthe
    Jan 2 at 13:29













  • Have you taken a look at "Custom UI Editor for Microsoft Office"? It's pretty solid tool for creating custom ribbons and allows the use of custom icons.

    – Frank Ball
    Jan 2 at 15:09











  • @FrankBall Yes, it says so in my post :) Thanks anyway.

    – Absinthe
    Jan 2 at 17:37














0












0








0








I'm trying to add two icons programmatically to a new ribbon group with VBA. I can add built in icons fine but can't figure out how to use my own files.



TLDR: The code below works if using built in icons with the imageMso attribute but not with custom icons using the image attribute or the getImage callback.



Here is the XML I'm using



<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab id='customTab' label='CP Analyzer' insertAfterMso='TabData'>
<group id='idCPA' label='CP Analyzer'>
<button id='customButton1' label='Select Column' size='large' onAction='SelectColumn' image='imgLabel' />
<button id='customButton2' label='Run Change Point Analyzer' size='large' onAction='RunCP' image='imgFast' />
</group>
</tab>
</tabs>
</ribbon>
</customUI>


I have two .png files (called imgLabel.png and imgFast.png) in the same folder as the add-in containing the above code. From using Microsofts Custom UI Editor to verify the syntax it appears image='myImageName' is correct and works when using the UI Editor, but not when used programmatically in VBA.



How can I reference these images?



Here's the full code, it works by modifying the main Excel.officeUI file:



Sub AddR

Dim hFile As Long
Dim path As String, filename As String, ribbonXML As String, user As String

hFile = FreeFile
user = Environ("Username")
path = "C:Users" & user & "AppDataLocalMicrosoftOffice"
filename = "Excel.officeUI"

ribbonXML = ' the XML above

Open path & filename For Output Access Write As hFile
Print #hFile, ribbonXML
Close hFile

End Sub


I've tried using the getImage callback described here which works fine for a stand-alone file but not as an Add-In which is the important bit for me here.



Specifically, using the Custom UI editor you can set the call back request in a custom UI XML file that gets embedded into the Excel file. Because I need this as an Add-In though I can't do that, since it's only the code that gets included (at least I can't find a way after searching on this all day). Hence my programatic attempt above to change the main Excel.officeUI file (and change it back to its default when the user disables the Add-In).










share|improve this question
















I'm trying to add two icons programmatically to a new ribbon group with VBA. I can add built in icons fine but can't figure out how to use my own files.



TLDR: The code below works if using built in icons with the imageMso attribute but not with custom icons using the image attribute or the getImage callback.



Here is the XML I'm using



<customUI xmlns='http://schemas.microsoft.com/office/2006/01/customui'>
<ribbon>
<tabs>
<tab id='customTab' label='CP Analyzer' insertAfterMso='TabData'>
<group id='idCPA' label='CP Analyzer'>
<button id='customButton1' label='Select Column' size='large' onAction='SelectColumn' image='imgLabel' />
<button id='customButton2' label='Run Change Point Analyzer' size='large' onAction='RunCP' image='imgFast' />
</group>
</tab>
</tabs>
</ribbon>
</customUI>


I have two .png files (called imgLabel.png and imgFast.png) in the same folder as the add-in containing the above code. From using Microsofts Custom UI Editor to verify the syntax it appears image='myImageName' is correct and works when using the UI Editor, but not when used programmatically in VBA.



How can I reference these images?



Here's the full code, it works by modifying the main Excel.officeUI file:



Sub AddR

Dim hFile As Long
Dim path As String, filename As String, ribbonXML As String, user As String

hFile = FreeFile
user = Environ("Username")
path = "C:Users" & user & "AppDataLocalMicrosoftOffice"
filename = "Excel.officeUI"

ribbonXML = ' the XML above

Open path & filename For Output Access Write As hFile
Print #hFile, ribbonXML
Close hFile

End Sub


I've tried using the getImage callback described here which works fine for a stand-alone file but not as an Add-In which is the important bit for me here.



Specifically, using the Custom UI editor you can set the call back request in a custom UI XML file that gets embedded into the Excel file. Because I need this as an Add-In though I can't do that, since it's only the code that gets included (at least I can't find a way after searching on this all day). Hence my programatic attempt above to change the main Excel.officeUI file (and change it back to its default when the user disables the Add-In).







excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 13:28







Absinthe

















asked Jan 2 at 10:55









AbsintheAbsinthe

1,93611536




1,93611536








  • 1





    Can you share what you have tried in VBA so far? My initial thought would be to generate an XML file with VBA

    – Zac
    Jan 2 at 11:44











  • @Zac Updated, thanks. I'm modifying the main Excel.officeUI file as I can't find a way to embed XML in an Add-In so that it affects the host instance of Excel while the Add-In is enabled.

    – Absinthe
    Jan 2 at 13:29













  • Have you taken a look at "Custom UI Editor for Microsoft Office"? It's pretty solid tool for creating custom ribbons and allows the use of custom icons.

    – Frank Ball
    Jan 2 at 15:09











  • @FrankBall Yes, it says so in my post :) Thanks anyway.

    – Absinthe
    Jan 2 at 17:37














  • 1





    Can you share what you have tried in VBA so far? My initial thought would be to generate an XML file with VBA

    – Zac
    Jan 2 at 11:44











  • @Zac Updated, thanks. I'm modifying the main Excel.officeUI file as I can't find a way to embed XML in an Add-In so that it affects the host instance of Excel while the Add-In is enabled.

    – Absinthe
    Jan 2 at 13:29













  • Have you taken a look at "Custom UI Editor for Microsoft Office"? It's pretty solid tool for creating custom ribbons and allows the use of custom icons.

    – Frank Ball
    Jan 2 at 15:09











  • @FrankBall Yes, it says so in my post :) Thanks anyway.

    – Absinthe
    Jan 2 at 17:37








1




1





Can you share what you have tried in VBA so far? My initial thought would be to generate an XML file with VBA

– Zac
Jan 2 at 11:44





Can you share what you have tried in VBA so far? My initial thought would be to generate an XML file with VBA

– Zac
Jan 2 at 11:44













@Zac Updated, thanks. I'm modifying the main Excel.officeUI file as I can't find a way to embed XML in an Add-In so that it affects the host instance of Excel while the Add-In is enabled.

– Absinthe
Jan 2 at 13:29







@Zac Updated, thanks. I'm modifying the main Excel.officeUI file as I can't find a way to embed XML in an Add-In so that it affects the host instance of Excel while the Add-In is enabled.

– Absinthe
Jan 2 at 13:29















Have you taken a look at "Custom UI Editor for Microsoft Office"? It's pretty solid tool for creating custom ribbons and allows the use of custom icons.

– Frank Ball
Jan 2 at 15:09





Have you taken a look at "Custom UI Editor for Microsoft Office"? It's pretty solid tool for creating custom ribbons and allows the use of custom icons.

– Frank Ball
Jan 2 at 15:09













@FrankBall Yes, it says so in my post :) Thanks anyway.

– Absinthe
Jan 2 at 17:37





@FrankBall Yes, it says so in my post :) Thanks anyway.

– Absinthe
Jan 2 at 17:37












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005072%2fprogramatically-set-custom-icon-to-added-ribbon-button%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005072%2fprogramatically-set-custom-icon-to-added-ribbon-button%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith