使用VBA在文件中插入和保存图像 - Excel 2013 [英] Using VBA to insert and keep images in file - Excel 2013

查看:257
本文介绍了使用VBA在文件中插入和保存图像 - Excel 2013的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的一位朋友制作一个宏,他需要在excel文档中导入一组图像,然后在其他计算机上使用此文档。我遇到的问题是,当在另一台计算机上打开此文档时,所有图像都消失了,而是你得到这些小错误标志,表明无法找到图像路径。

I'm working on a macro for a friend of mine who needs to import a set of images in an excel document and later use this document on other computers. The problem I encountered is that when opening this document on a different computer, all the images are gone and instead you get these little error signs, indicating that the image path could not be found.

我在自己的计算机上开发了宏,我有Excel 2007,对我来说,代码运行得非常好。我的朋友使用Excel 2013,显然,这两个版本如何处理图像导入和保存似乎存在重大差异。

I have developed the macro on my own computer where I have Excel 2007 and for me, the code works perfectly fine. My friend uses Excel 2013 and apparently, there seems to be a major difference on how those 2 versions deal with the image importing and saving.

总体而言,我发现了两种不同的方式如何插入图像。我试过的第一个类似于:

Overall, I found 2 different ways how to insert images. The first one I tried was something similar to this:

Set pic = ActiveSheet.Pictures.Insert("C:\documents\somepicture.jpg")

第二种做法如下:

Set pic = Application.ActiveSheet.Shapes.AddPicture("C:\documents\somepicture.jpg", False, True, 1, 1, 1, 1)

在第2种方法的文档中,据说是第3次参数(这里是真的)负责用文档保存图片。

In the documentation for this 2nd approach it is said that the 3rd paramenter (which is True here) is responsible for saving the picture with the document.

但是,这两种方法在最终结果中看起来大致相同:它们的工作正常如果他们在我的朋友的PC上使用Excel 2013执行它们将无法工作。所以我需要的是新版本的Excel版本的解决方法(我从Excel 2010向上阅读,有一个bug或类似的东西使用这些图像导入方法)。

However, both these approaches look more or less the same in the end result: They work fine for me but won't work if they are executed on my friends pc with Excel 2013. So what I need is a work-around for the newer Excel versions (I read somewhere that from Excel 2010 upwards, there is a bug or something like that with these image import methods).

推荐答案

我n我的所有用途,使用插入添加图片会引用硬盘上的文件,无论出于何种原因,如果您希望将图像嵌入到必须的文件中添加一个形状,然后使用 AddPicture (就像你使用的那样)将图像放在形状上,我从来没有遇到任何问题。

In all my uses, Adding a picture with Insert makes a reference to a file on your harddrive, for whatever reason if you want the image to be embedded in the file you have to add a shape and then put the image on the shape using the AddPicture (like you use), I have never had any issues with this.

此外,你给图片的高度和宽度为1像素,你几乎永远无法看到更高的真实设置如下:

Also you are giving the picture a height and width of 1 pixel, You will almost never be able to see that true setting that higher as below:

Application.ActiveSheet.Shapes.AddPicture "C:\documents\somepicture.jpg", False, True, 1, 1, 100, 100

我觉得它一直都在工作,你从来没有看过这张照片因为它太小了。

I have a feeling it was working all along and you just never saw the picture cause it was too small.

这篇关于使用VBA在文件中插入和保存图像 - Excel 2013的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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