路径放在A列,B列将输出图片。按ALT+F11打开宏IDE,输入如下语句并执行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27  | Function IsExitAFile(filespec)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.fileExists(filespec) Then
        IsExitAFile = True
        Else: IsExitAFile = False
    End If
End Function
 
Sub Macro1()
    Dim i As Integer
    Dim path As String
    For i = 1 To 5700
        Range("B" & i).Select
 
        path = "d:\path\to\pic\" + Range("a" & i).Value
 
        If IsExitAFile(path) Then
 
            ActiveSheet.Pictures.Insert(path).Select
            Selection.Width = Range("b" & i).Width
            Selection.Height = Range("b" & i).Height
 
        End If
 
    Next i
End Sub |