VBA Word - 按下按钮时插入嵌入的图像

时间:2014-11-26 12:04:57

标签: vba ms-word word-vba

我制作了一个包含几个按钮的自定义功能区。这些按钮应该在选择中将不同种类的符号或图片插入到文档中。

由于这是一个模板,我希望在没有图像文件夹的情况下使用模板,而是将图像以某种方式嵌入到文档的结构中。

我想到了两种可行的方法。

1. Create a portion of the template document which contains all 
   the images and hide it somehow

2. Add the images to the zip structure of the file, in the \word\media folder
   and load the images from there. If even possible...???

实现这种效果的最佳/最简单方法是什么?

1 个答案:

答案 0 :(得分:0)

实际上,您使用的版本可能并不重要(除非是2003/4或之前版本)。通常,执行此操作的方法是创建构建块(或快速部分,这是他们在Word 2010中调用的内容)。

此链接说明了您将采取的基本步骤(尽管如果您不使用Word 2010/13,详情会有所不同):https://support.office.com/en-SG/Article/Word-2010-Create-a-new-template-cb17846d-ecec-49d4-82ea-a6f5e3e8b9ae#__toc278287931

基本上,您将图像粘贴到文档中,选择它,将其添加到快速部件/构建块库中,但将其保存到模板(当时必须打开)。然后,用户应该能够从“快速部件”按钮访问它们。或者,如果您根据用户执行的操作以编程方式插入它们,则可以执行以下操作:

objTemplate.BuildingBlockEntries("flower").Insert selection.Range