|
原帖由 lbl016 于 2010-9-12 07:13 发表
楼主的问题是导出图片,我现在的问题是想导入图片。请问:怎样批量导入图片,比如将D盘的"图片"文件夹中的图片导入到B列,并且图片的名称与A列的货号相对应名称,应如何设置宏代码。
这个更简单啊。参考:
http://club.excelhome.net/thread-611346-1-1.html
改进版,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 |
|