|
楼主 |
发表于 2010-9-7 16:37
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
改进版,39种图片格式自动导入图片及名称
Sub 单元格自动插入图片()
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,"
Pf = Pf & "wdp,wmf,wmz,"
K = InputBox("插入行数,1=按列挿入", "插入行数", 1)
If K = "" Then Exit Sub
Dim Rng As Range: Set Rng = ActiveCell
OpenFile = Application.GetOpenFilename("Picture Files(*.*),*.*", , "Get Picture from here!")
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(Pf, LCase(Right(Filename, Len(Filename) - InStrRev(Filename, ".")))) > 0 Then
Rng.Cells(1 + n \ K, n Mod K + 1).Select
ActiveCell = Filename 'Left(Filename, InStrRev(Filename, ".") - 1)
ActiveSheet.Pictures.Insert(myDir & Filename).Select
With Selection
.Placement = xlMoveAndSize
.ShapeRange.LockAspectRatio = msoFalse
.Top = ActiveCell.Top
.Left = ActiveCell.Left
.Height = ActiveCell.Height
.Width = ActiveCell.Width
End With
n = n + 1
End If
Filename = Dir
Loop
Application.ScreenUpdating = True
Rng.Select
End Sub
[ 本帖最后由 香川群子 于 2010-9-12 09:44 编辑 ] |
|