excel批量插入图片(宏方式)

Sub 插入图片()
    Dim pic As String, n As Long
    Dim picTemp As Picture
    pic = Dir("D:\pictures\*.*") '选择目录
    While pic > ""
      '仅列出jpg/bmp和gif格式的文件名
      If pic Like "*.jpg" Or pic Like "*.bmp" Or pic Like "*.gif" Then
      n = n + 1
      Range("a" & n).Select
      Set picTemp = ActiveSheet.Pictures.Insert("D:\pictures\" & pic)
      picTemp.Placement = xlMoveAndSize
      With picTemp.Select
        Selection.ShapeRange.LockAspectRatio = 0
        Selection.ShapeRange.Width = 10
        Selection.ShapeRange.Height = 10
      End With
      End If
      pic = Dir()
    Wend
End Sub

这个是用宏方式插入的,需要用时请修改"D:\pictures\"为自己的图片的路径。excel打开宏的方式可以百度一下。

你可能感兴趣的:(杂谈)