将图像从一个工作簿复制到另一工作簿 [英] Copy image from one workbook to another workbook

查看:113
本文介绍了将图像从一个工作簿复制到另一工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sheet1中有一个图像在合并的单元格范围S1:V8中.

I have an image in a sheet1 in a merged cell range S1:V8.

我不知道这张图片的名称,因为每次我们从模板创建新的Excel文件时,我们都会在该区域粘贴不同的图片.

I don't know the name of this picture because we paste different pictures in the area each time we create a new Excel file from a template.

我想将此工作簿或另一个工作簿中此范围内的图片复制到单元格A6中名为数据库"的工作表中.

I want to copy the picture in this range in this workbook or another workbook, to a sheet called "Database" into cell A6.

我找到了几个示例,但我们必须知道图片名称.

I've found several examples but we must know the picture name.

我想要第一张照片.我想我可以检查范围是否有照片.然后选择第一张图片并将其粘贴到其他工作簿中.

I want the first picture. I imagine I can check if the range has pictures. Then select the first picture and paste it in the other workbook.

我唯一不能做的就是在复制范围内选择图片.

The only thing I can't do is to select the picture inside the range for copying.

如有可能,奖励功能:
-之后,我想将其调整为单元格尺寸,但要保持宽高比
-我想将其压缩到96 dpi后
-此文件将有几张图片.如果有人修改图片尺寸,是否有办法将它们调整为每个单元格的大小? (在单元格A6中有一张图片,在单元格A7中有另一张图片,...,例如,有人可以在A20中更改图片的大小)

Bonus features if possible:
- After that I want to resize it to the cell dimension, but maintaining the aspect ratio
- After I want to compress it to 96 dpi
- This file will have several pictures. Is there a way to resize them all to each cell were they are in case of someone modifies the pictures dimension? (there will be a picture in Cell A6, another in cell A7,..., and someone could change the size of the picture in A20 for example)

帖子也在MrExcel论坛中.

This post is also in the MrExcel forum.

推荐答案

目前尚不清楚您所指的图片是在单元格中"还是在单元格上方浮动.据我所知,在单元格中"具有图片的唯一方法是将其放在单元格的注释中(实际上,是用作注释文本的背景图片).在任何一种情况下,使用VBA对其进行操作的关键都是获取其参考.如果您首先选择单元格区域,则下面的代码将标识以上两种情况之一的存在,如gif动画所示.不幸的是,据我所知,您所能做的就是通过VBA在评论中添加背景图片.

It's not clear whether the picture you are referring to is "in the cell" or floating above the cells. As far as I know, the only way to have a picture "in a cell" is to have it within the comment of the cell (actually, intended as a background picture for comment text). In either case, the key to manipulating it using VBA would be to get a reference for it. The following code will identify the presence of either of the above cases if you first select the region of cells, as shown in the animated gif. Unfortunately, as far as I know, all you can do is add background pictures to comments via VBA.

Option Explicit
Sub testForPicturesOrComments()
Dim p As Picture, r As Range, hasComment As Boolean
For Each p In ActiveSheet.Pictures
  MsgBox ("There's a picture called " & p.Name)
Next p
For Each r In Selection
  On Error Resume Next
  hasComment = r.Comment.Parent.Address = r.Address
  'Reset Run Time Errors
  On Error GoTo 0
  If hasComment Then
  MsgBox ("There's a comment in " & r.Address _
  & " with a shape.ID = " & r.Comment.Shape.ID)
    hasComment = False
  End If
Next r
End Sub

这篇关于将图像从一个工作簿复制到另一工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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