来自customUI的VBA功能区回调图像

时间:2018-07-30 07:48:56

标签: excel vba ribbon

我正在尝试控制保存在XLAM插件中的按钮图像。我想根据条件的某些值在按钮上显示不同的自定义图像。看起来像这样:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" >
<ribbon>
<tabs>
<tab id="CustomTab" getLabel="GetLabel">
<group id="GroupCustom" getLabel="GetLabel">
<button id="CustomBtn" getLabel="GetLabel" onAction="RunMacro" getImage="GetImage"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

我已将图片保存在加载项中:

<?xml version="1.0" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Id="custom_image" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="images/custom_image.jpg"/>
</Relationships>

如果这样写,那就行得通

<button id="CustomBtn" getLabel="GetLabel" onAction="RunMacro" Image="custom_image"/>

But I need to control image from VBA. This works:
Sub GetImage(control As IRibbonControl, ByRef Image)
Select Case control.ID
Case "CustomBtn": Set Image = LoadPicture("C:\SomeDirectory\custom_image.jpg")
End Select
End Sub

但是我不想将图像存储在外部位置。 这不起作用:

Case "CustomBtn": Image = "custom_image"

任何人都可以告诉我,是否可以使用VBA回调来控制AddIn中保存的图像?还是只有一种方法可以制作两个按钮并控制其中的可见性?

0 个答案:

没有答案
相关问题