|
Sub BatchExportPictures()
Dim path As String
Dim folder As Object
Dim file As Object
Dim i As Integer
path = "C:\Pictures\" '图片所在文件夹路径
Set folder = CreateObject("Scripting.FileSystemObject").getfolder(path)
For Each file In folder.Files
If Right(file.Name, 4) = ".jpg" Or Right(file.Name, 5) = ".jpeg" Or Right(file.Name, 4) = ".png" Or Right(file.Name, 4) = ".bmp" Then '判断文件是否为图片类型
i = i + 1
ActiveSheet.Shapes.AddPicture Filename:=file.Path, linktofile:=msoFalse, savewithdocument:=msoCTrue, _
Left:=ActiveSheet.Cells(i, 1).Left, Top:=ActiveSheet.Cells(i, 1).Top, Width:=100, Height:=100 '导入图片到Excel中
End If
Next file
'将Excel中的图片(无损)批量导出到指定文件夹
ActiveSheet.Shapes.Range(Array(1, 1, i, 1)).Export "C:\ExportedPictures\", ppSaveAsPNG
End Sub |
|