|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这样试试看
原帖由 5465465465 于 2010-9-8 11:15 发表
试验了一下,确实很好用,高手。。。。。但我还有个要求,比如说有两行,第一行是姓名,第二行能不能将按第一行的姓名插入照片(照片以姓名命名),对号入座。谢谢~!
Sub 选择范围后按姓名插入照片()
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
[ 本帖最后由 香川群子 于 2010-9-9 18:28 编辑 ] |
|