如何在Office文件中嵌入图像以进行自定义功能区 [英] How to embed images in Office file for custom Ribbon

查看:524
本文介绍了如何在Office文件中嵌入图像以进行自定义功能区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Excel的自定义功能区扩展,其中控件需要不同的自定义图像。我设法使用我的文件系统中的一些图像,但是我想将这些图像嵌入到.xlsm文件中。
可以这样做,并从更新控件图像的VBA代码中引用它们。

I am developing a custom ribbon extension for Excel, in which a control requires different custom images. I managed to use some images located in my filesystem, but I would like to embed these images inside the .xlsm file. Is it possible to do it and to reference them from the VBA code that updates the image of the control?

为了测试的目的,这是XML定义我的自定义功能区:

For test purposes, this is the XML that defines my custom ribbon:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="ribbonLoaded">
  <ribbon>
    <tabs>
      <tab idMso="TabHome" >
        <group id="customGroup1" label="My Group" insertAfterMso="GroupFont">
          <button id="customButton1" label="Click Me" size="large" onAction="Macro1" getImage="getButtonImage"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

这是更改 customButton1 control:

And this is the macro that change the image of the customButton1 control:

Dim imgIndex As Long

Public Sub getButtonImage(ByVal control As IRibbonControl, ByRef Image)
Select Case control.ID
  Case "customButton1"
    Set Image = LoadPicture("img" + Trim(Str(imgIndex)) + ".bmp")
    imgIndex = (imgIndex + 1) Mod 2
  End Select
End Sub

我试图在.xlsm内添加bmp文件,并引用它们更新关系文件(.rels),但是我不知道如何从VBA中引用它们,最重要的是当我用Excel打开文件并保存它,他们将被自动删除...

I tried to add the bmp files inside the .xlsm and reference them updating the relationships file (.rels), but I don't know how to reference them from VBA and most important, when I open the file with Excel and save it, they are automatically deleted...

任何帮助是赞赏!

推荐答案

如果图像嵌入在customUI中,则不需要VBA将其添加到控件。只需在图像中使用相同的图像ID =

If the image is embedded in the customUI, you do not need VBA to add them to a control. Just use the same ID for the image in an image tag:

<button id="button1" label="Test" size="large" image="TestID" onAction="ButtonOnAction" />

我的示例使用ID为TestID的映像,它必须在customUI XML中找到 - 在 customUI 节点rel =nofollow>自定义UI编辑器查找或更改图像ID(或使用编辑器添加新图像)。

My sample is adressing the image with ID "TestID", which must be found in the customUI XML - expand the customUI node in the Custom UI Editor to find or change the image ID (or use the editor to add a new image).

这篇关于如何在Office文件中嵌入图像以进行自定义功能区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆