当前位置:首页 » 图片知识 » xl如何插入图片链接
扩展阅读
女生和渣男搞笑图片 2023-08-31 22:07:09
嘻嘻长什么样图片 2023-08-31 22:06:10

xl如何插入图片链接

发布时间: 2023-06-15 11:18:07

‘壹’ excel表格如何使用宏在当前单元格内插入图片

代码如下先给你,我先声明下,我也是之前需要这个操作在网上找的,可以实现你的功能,很好用。

具体用法:

  1. 打开excel的VB,把代码复制进去。

  2. 在A列输入需要插入照片的名称,然后选定这些有名称的单元格(重点!要选定)。

  3. 然后运行宏,在弹出的对话框选【否】,意思就是在名称的右边插入图片,上面的汉字应该也能看懂。

  4. 然后会出来一个对话框让你选择路径,选择你放照片的那个文件夹,点击文件夹里的任意一张照片点【打开】。

  5. 然后照片就插进去了,而且是每张照片都填满单元格。

  6. 建议提前把单元格的大小设置好然后再运行宏。

    如下看我的示例,功能真鸡儿强大,再次膜拜下VB大神。

Sub A()

Dim Rng As Range

Set Rng = Selection

K = MsgBox("Yes=按姓名行下插入,No=按姓名列右挿入,Cancel=直接覆盖插入", vbYesNoCancel)

If K = vbYes Then

r = 1: c = 0

ElseIf K = vbNo Then

r = 0: c = 1

Else

r = 0: c = 0

End If

Pf = "ai,"

Pf = Pf & "bmp,bmz"

Pf = Pf & "cdr,cgm,"

Pf = Pf & "dib,dwg,dxf,"

Pf = Pf & "emf,emz,eps,exf,exif,"

Pf = Pf & "fpx,"

Pf = Pf & "gfa,gif,"

Pf = Pf & "hdr,"

Pf = Pf & "ico,"

Pf = Pf & "jfif,jpe,jpeg,jpg,"

Pf = Pf & "pcd,pct,pcx,pcz,pict,png,psd,"

Pf = Pf & "raw,rle,"

Pf = Pf & "svg,"

Pf = Pf & "tga,tif,tiff,"

Pf = Pf & "ufo,"

Picformat = Pf & "wdp,wmf,wmz,"

OpenFile = Application.GetOpenFilename("Picture Files(*.*),*.*", , "打开目的档案夹后选择任一图片即可指定资料夹。或按取消则会将当前档所在资料夹认作指定资料夹。")

If OpenFile = False Then

myDir = ThisWorkbook.Path & ""

Else

myDir = Left(OpenFile, InStrRev(OpenFile, ""))

End If

Application.ScreenUpdating = False

Filename = Dir(myDir)

Do While Filename <> ""

If InStr(Picformat, LCase(Right(Filename, Len(Filename) - InStrRev(Filename, ".")))) > 0 Then

PicName = Left(Filename, InStrRev(Filename, ".") - 1)

Rng.Select

On Error Resume Next

Selection.Find(What:=PicName, After:=ActiveCell, LookAt:=xlWhole).Activate

If Err.Number <> 0 Then

Err.Clear

Else

ActiveSheet.Pictures.Insert(myDir & Filename).Select

With Selection

.Placement = xlMoveAndSize

.ShapeRange.LockAspectRatio = msoFalse

.Top = ActiveCell.Offset(r, c).Top

.Left = ActiveCell.Offset(r, c).Left

.Height = ActiveCell.Offset(r, c).Height

.Width = ActiveCell.Offset(r, c).Width

End With

End If

End If

Filename = Dir

Loop

Rng.Select

End Sub

‘贰’ 如何把图片镶嵌在EXCEL表格内固定 让自动筛选时图片和名称能对应的上

你插入图片后把图片格式设置“大小和位置随单元格而变”。这样筛选时就能对应得上了。
不过要注意,这样设置以后你改变单元格大小的时候图片也会改变。

另,如果要一次性选中所有图片,可用“定位”功能,F5或者CTRL+G,然后选中“对象”就可以。