|
原帖由 中国-龙 于 2010-9-9 22:39 发表
非常感谢香川群子对我无私的帮助,谢谢了!
其实这项工作困扰我很长时间了, 只因水平太低,想弄,却一直弄不好。现在合盘提出,希望您在百忙之中给予指点迷津。
帮你修改了专用的代码,
不过,最好还是自己能看懂,以便将来能自己维护。
Sub AutoPicInsert()
Dim Rng As Range
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(*.*),*.*", , "Select a Picture, cancel to use thisworkbook path.")
If OpenFile = False Then
myDir = ThisWorkbook.Path & "\"
Else
myDir = Left(OpenFile, InStrRev(OpenFile, "\"))
End If
r = Range("照片").Row - Range("姓名").Row
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)
On Error Resume Next
Range("姓名").EntireRow.Find(What:=PicName, After:=Range("姓名"), LookAt:=xlWhole).Activate
If Err.Number <> 0 Then
Err.Clear
Else
c = ActiveCell.Column Mod 2
ActiveCell.Offset(r + c, 0).Select
Set Rng = Selection
rh = Rng.Height
rw = Rng.Width
If Rng(1, 1) <> "" Then GoTo ExtToNext Else Rng(1, 1) = Filename
ActiveSheet.Pictures.Insert(myDir & Filename).Select
With Selection
.Placement = xlMoveAndSize
.ShapeRange.LockAspectRatio = msoFalse
ph = .Height
pw = .Width
tm = rh / ph '高固定
'tm = rw / pw '幅固定
'tm = IIf(rh / ph < rw / pw, rh / ph, rw / pw) '取高幅比最小
.Height = .Height * tm
.Width = .Width * tm
.Top = Rng.Top + (rh - .Height) / 2
.Left = Rng.Left + (rw - .Width) / 2
End With
End If
End If
ExtToNext:
Filename = Dir
Loop
End Sub
稍后上传附件。
[ 本帖最后由 香川群子 于 2010-9-10 21:57 编辑 ] |
|