|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 chzsh 于 2023-2-6 16:30 编辑
Sub save_pic() '导出所有图片
Dim shap As Shape
Dim i As Integer
With ActiveSheet
For i = 1 To .Shapes.Count
Set shap = .Shapes(i)
shap.Copy
With .ChartObjects.Add(0, 0, shap.Width, shap.Height).Chart
.Parent.Select
.Paste
.Export ThisWorkbook.Path & "\" & i & ".jpg"
.Parent.Delete
End With
Next
End With
End Sub
Sub demo() '导出选中图片
Dim i, shp As Object
On Error GoTo AA
With ActiveSheet
If Selection.ShapeRange.Count > 1 Then
For Each shp In Selection
i = i + 1
shp.Copy
With .ChartObjects.Add(0, 0, shp.Width, shp.Height).Chart
.Parent.Select
.Paste
.Export ThisWorkbook.Path & "\AAA\" & i & ".jpg"
.Parent.Delete
End With
Next
ElseIf Selection.ShapeRange.Count = 1 Then
Set shp = Selection.ShapeRange(1)
shp.Copy
With .ChartObjects.Add(0, 0, shp.Width, shp.Height).Chart
.Parent.Select
.Paste
.Export ThisWorkbook.Path & "\AAA\ 1.jpg"
.Parent.Delete
End With
End If
End With
Exit Sub
AA:
MsgBox "请选择要保存的图形!"
End Sub |
|