电子表格中已插入了很多的对象,如何将这些对象批量导出到指定的文件夹中,用vba。
这是chatgpt写的但有问题,并且插入的对象并不一定是图片
folderPath = "C:\ExportedObjects" '设置导出文件夹路径
If Dir(folderPath, vbDirectory) = "" Then '如果文件夹不存在,则创建
MkDir folderPath
End If
i = 1
For Each obj In ActiveSheet.Shapes '遍历所有对象
If obj.Type = msoPicture Or obj.Type = msoOLEControlObject Then '如果是图片或OLE对象
obj.CopyPicture xlScreen, xlPicture '复制对象
With New Picture '创建新的Picture对象
.Paste '粘贴复制的对象
.SaveAs folderPath & "Object" & i & ".jpg" '保存为jpg文件,文件名包含序号
End With
i = i + 1 '增加序号
End If
Next obj