Sub ExportSelectedFlowchartAsImage()
Dim shp As Shape
Dim chartName As String
Dim filePath As String
Dim picRange As Range
Dim exportFolder As String
' 设置导出图片的文件夹路径
exportFolder = "C:\Path\To\ExportFolder\" ' 修改为你的实际路径
' 确保选中至少一个形状
If Selection.ShapeRange.Count = 0 Then
MsgBox "请先选择一个流程图形状。"
Exit Sub
End If
' 获取选中的形状
Set shp = Selection.ShapeRange(1)
' 设置导出文件路径和文件名
filePath = exportFolder & "Flowchart_" & shp.Name & ".png"
' 将形状导出为图片
shp.Copy
With ActiveSheet.ChartObjects.Add(Left:=shp.Left, Width:=shp.Width, Top:=shp.Top, Height:=shp.Height)
.Chart.ChartArea.Clear
.Chart.Paste
.Chart.Export Filename:=filePath, FilterName:="PNG"
.Delete
End With
MsgBox "流程图已导出为图片:" & filePath
End Sub