|
楼主 |
发表于 2014-6-11 18:14
|
显示全部楼层
zhaogang1960 发表于 2014-6-11 17:13
请参考:
谢谢你们,测试成功,同时我有一个疑问,我用我的代码只能导出部分图片,用了你们的代码可以全部导出来,很奇怪,我把我的代码放出来,请你们帮忙找不足。
请参考:
Sub 导出图片() ' 从excel中导出图片到文件夹
Dim i As Long
Dim nm$, n&, m&, fd
Dim cht As ChartObject
Dim sh As Shape
Dim strPath As String
Dim strPath2 As String
Set fd = Application.FileDialog(msoFileDialogFolderPicker) '允许用户选择一个文件夹
If fd.Show = -1 Then
strPath = fd.SelectedItems(1) '选择之后就记录这个文件夹路径名称
End If
For i = 1 To ActiveSheet.Shapes.Count
Set sh = ActiveSheet.Shapes(i)
If sh.Type = 13 Then
n = sh.TopLeftCell.Offset(-1, 0).Row
m = sh.TopLeftCell.Offset(-1, 0).Column
nm = Cells(n, m).Text
sh.CopyPicture
Set cht = ActiveSheet.ChartObjects.Add(0, 0, 150, 200)
With cht
.Chart.Paste
.Chart.Shapes(1).Height = 200
.Chart.Shapes(1).Width = 150
If Len(nm) <> 0 Then strPath2 = strPath & "\" & nm & ".jpg"
.Chart.Export strPath2, "JPG"
End With
End If
Next
End Sub
|
|