Excel宏放置图像,但是当其他人打开工作簿时它们不会出现 [英] Excel macro places images, but they do not appear when others open the workbook

查看:191
本文介绍了Excel宏放置图像,但是当其他人打开工作簿时它们不会出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在闲逛,拼命地拼凑了一大笔宏观的工作,从互联网上可以找到。目的是最终格式化报告。



这部分代码从单元格中获取值,并在给定的文件夹中找到分别命名的图像文件,然后它将图像插入到某个单元格中。 (我知道这不是技术上的插入,但仍然是。)



问题是其他人需要查看这些报告,但是当我发送工作簿给他们我不知道如何纠正这个,这是一个很大的事情。开始你,请帮我找出一个办法,让其他员工能够看到图像!我的工作可能依赖于它! :(

  Dim pictureNameColumn As String 
Dim picturePasteColumn As String
Dim pictureName As String
Dim lastPictureRow As Long
Dim pictureRow As Long
Dim pathForPicture As String
pictureNameColumn =A
picturePasteColumn =B
pictureRow = 4
lastPictureRow = Cells(Rows.Count,pictureNameColumn).End(xlUp).Row
pathForPicture =C:\Users\desid\reportimages\
Do While(pictureRow< = lastPictureRow)
pictureName = Cells(pictureRow,A)
If(pictureName<> vbNullString)Then
If(Dir(pathForPicture& pictureName&.jpg)& ; vbNullString)然后
单元格(pictureRow,picturePasteColumn)。选择
ActiveSheet.Pictures.Insert(pathForPicture& pictureName&.jpg)。选择
选择
。 Left = Cells(pictureRow,picturePasteColumn).Left + 30
.Top = Cells(pictureRow,picturePasteColumn).Top + 3
.ShapeRange.LockAspectRatio = msoTrue
.ShapeRange.Height = 90#
.ShapeRange.Width = 90#
.ShapeRange.Rotation = 0#
结束


解决方案

而不是使用 ActiveSheet.Pictures.Insert 插入图片,尝试使用此方法嵌入它。还请注意,单元格不接受字母作为列名称,它需要列数,以便A变为1:

  Dim repPic as Shape 
Dim pictureNameColumn As Long
Dim picturePasteColumn As Long
Dim Lft as Single
Dim Tp as Single
Dim Wdth as Single
Dim Hgth as Single
pictureNameColumn = 1
picturePasteColumn = 2
Lft = Cells(pictureRow,picturePasteColumn).Left + 30
Tp = Cells(pictureRow,picturePasteColumn).Top + 3
Wdth = Cells(pictureRow,picturePasteColumn).Width
Hgth = Cells(pictureRow,picturePasteColumn).Height
设置repPic = Application.ActiveSheet.Shapes.AddPicture(pathForPicture& pictureName&。 jpg,False,True,Lft,Tp,Wdth,Hgth)

这将让您保存图片在文件本身。您将必须弄清楚如何使用wdth和hgth来计算图片的大小,因为使用此方法,您必须在插入图片时指定宽度和高度。我的建议的解决方案是在代码中,但它可能不适用于您的设置。



希望这有帮助,如果它确实答案被接受。祝你好运!


I have been slaving away, trying desperately to piece together a huge macro for my job from what I can find on the internet. The aim is to format reports, ultimately.

This part of the code takes the value from a cell, and finds the respectively named image file in a given folder, then it "inserts" the image into a certain cell. (I know it's not technically inserting it, but still.)

The problem is that other people need to view these reports, but the images do not show when I send the workbook to them. I have no idea how to rectify this and it is such a big deal. am BEGGING YOU, please help me figure out a way to do this so that other employees will be able to see the images! My job may depend on it! :(

Dim pictureNameColumn As String
Dim picturePasteColumn As String
Dim pictureName As String
Dim lastPictureRow As Long
Dim pictureRow As Long
Dim pathForPicture As String
pictureNameColumn = "A"
picturePasteColumn = "B"
pictureRow = 4
lastPictureRow = Cells(Rows.Count, pictureNameColumn).End(xlUp).Row
pathForPicture = "C:\Users\desid\reportimages\" 
Do While (pictureRow <= lastPictureRow)
pictureName = Cells(pictureRow, "A")
If (pictureName <> vbNullString) Then
If (Dir(pathForPicture & pictureName & ".jpg") <> vbNullString) Then
Cells(pictureRow, picturePasteColumn).Select
ActiveSheet.Pictures.Insert(pathForPicture & pictureName & ".jpg").Select
With Selection
.Left = Cells(pictureRow, picturePasteColumn).Left + 30
.Top = Cells(pictureRow, picturePasteColumn).Top + 3
.ShapeRange.LockAspectRatio = msoTrue 
.ShapeRange.Height = 90#
.ShapeRange.Width = 90#
.ShapeRange.Rotation = 0#
End With

解决方案

Instead of inserting picture with ActiveSheet.Pictures.Insert, try embedding it with this method. Please also note that Cells does not accept letters as column names, it requires numbers of columns, so that "A" becomes 1:

Dim repPic as Shape
Dim pictureNameColumn As Long
Dim picturePasteColumn As Long
Dim Lft as Single
Dim Tp as Single
Dim Wdth as Single
Dim Hgth as Single
pictureNameColumn = 1
picturePasteColumn = 2
Lft = Cells(pictureRow, picturePasteColumn).Left + 30
Tp = Cells(pictureRow, picturePasteColumn).Top + 3
Wdth = Cells(pictureRow, picturePasteColumn).Width
Hgth = Cells(pictureRow, picturePasteColumn).Height
Set repPic = Application.ActiveSheet.Shapes.AddPicture(pathForPicture & pictureName & ".jpg", False, True, Lft,Tp,Wdth,Hgth)

This will let you save the pictures in the file itself. You will have to figure out how to work out the size of the picture with wdth and hgth, because with this method you have to specify width and height at the moment of inserting the picture. My suggested solution is in the code, but it might not work for your setup.

Hope this helps, and if it does please mark the answer as accepted. Good luck!

这篇关于Excel宏放置图像,但是当其他人打开工作簿时它们不会出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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