Excel VBA:将图片从图像控件复制到activeX对象 [英] Excel VBA: Copying Pictures from image controls to activeX objects

查看:1759
本文介绍了Excel VBA:将图片从图像控件复制到activeX对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列图像需要在两种形式(通过图像控件)和工作表(通过activeX图像控件)上多次显示。我知道我可以在外部保存文件并使用 loadpicture 方法;但是如果可能的话我还有一些想要避免的事情。

I have a series of images that I need to display multiple times on both forms (via image controls) and on worksheets (via activeX image controls). I know that I could keep the files externally and use the loadpicture method; but there is something I want to avoid if possible.

我也知道我可以保存并加载 - 但我再也不想使用外部文件写来执行任务。理想情况下,所有内容都将保持嵌入并隐藏在文件本身中。

I also know I could save and load- but again I would rather not use an external file write to perform the task. Ideally, everything will stay embedded and hidden within the file itself.

我认为使用剪贴板可能有一个解决方案 - 但我无法使语法工作。对象始终嵌入在相同的位置;它永远不会移动或改变大小或其他属性(超出.visible)。所以我真正想做的就是简单的事情;

I think there maybe a solution in using the clipboard- but I couldn't get the syntax to work. The object is embedded always in the same location(s); it never moves or changes size or other properties (beyond .visible). So what I would really like to do is something simple like;

Sheet1.oleobjects("toImage").object.picture = frm1.fromImage.picture

**编辑:**

我想我我找到了解决方案;但是仍然有一个相关的问题。

** **
I think I've found a solution to this; but still have a related question.

如果我在一张纸上嵌入一系列的activeX图像,我发现我能做我想做的事情。然后在我想要的实际控件/对象中引用它们。所以;

I worked out that I could do what I want if I embed a series of activeX images on a sheet; then reference them in the actual controls / objects I want. So;

Sheet1.oleobjects("toImage").object.picture=Sheet1.oleobjects("FromImage").object.picture

frm1.Controls("toImage").picture = Sheet1.oleobjects("FromImage").object.picture

但是,当我尝试使用插入的图片(形状对象)做同样的事情时,下面的代码不起作用;

But, the below doesn't work when I try to do the same using an inserted picture (a shape object);

frm1.toImage.picture =  sheet1.shape("FromImage").picture

..是无效的语法。似乎我唯一可以做的就是复制它们 - 我不能使用它们来设置另一个对象的图片而不使用剪贴板。

..isn't valid syntax. It seems the only thing I can do with them is copy them- I couldn't use them to set the picture of another object without using the clipboard.

上面的解决方案适合我(使用一系列activeX图像对象而不是图片) - 但我很好奇为什么我不能使用标准图片(形状)。

The solution above works for me (using a series of activeX image objects rather than pictures)- but I am curious why I can't do with using a standard picture (shape).

推荐答案

如果要在Excel工作表中添加图片,请使用以下内容:

(您可以更改 ActiveSheet 到您最喜欢的表格)

If you want to add a picture to your Excel sheet use something like this:
(You can change ActiveSheet to your favorite sheet)

Dim aSheet As Worksheet
Dim aShape As Shape
Set aSheet = ActiveSheet
Set aShape = aSheet.Shapes.AddPicture("<FileName>", msoFalse, msoTrue, 120, 120, 200, 200)

有关更多详情:


功能AddPicture (文件名为String,LinkToFile As MsoTriState,SaveWithDocument As MsoTriState,Left as Single,Top as Single,Width As Single,单身高度)作为形状

Function AddPicture(Filename As String, LinkToFile As MsoTriState, SaveWithDocument As MsoTriState, Left As Single, Top As Single, Width As Single, Height As Single) As Shape

函数AddPicture2 (文件名为字符串,LinkToFile为MsoTriState,SaveWithDocument为MsoTriState,左为单,顶部为单,宽度为单,高度为单,压缩为MsoPictureCompress)为形状

Function AddPicture2(Filename As String, LinkToFile As MsoTriState, SaveWithDocument As MsoTriState, Left As Single, Top As Single, Width As Single, Height As Single, Compress As MsoPictureCompress) As Shape






和如果您想将图片加载到表单上的图像组件:

(添加图片表单中的组件[:Image1])


And if you want to load a picture to your Image component on your form :
(Add an Image component to your form [: Image1])

Set Image1.Picture = LoadPicture("<FileName>")

这篇关于Excel VBA:将图片从图像控件复制到activeX对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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