|
各位前辈好!
我自己编写了一段代码,可以导出Excel图表,另存为JPG图片,但是图片是空白的,不知道哪里出了问题,还想请教论坛里各位前辈指点迷津。代码如下:
Sub Try()
Dim iShape As Shape, iChart As ChartObject, FileName As String
For i = 1 To 3 '假设有三个,循环开始
Set iShape = Sheets(1).Shapes(i)
iShape.CopyPicture Appearance:=xlScreen, Format:=xlPicture '复制到剪贴板
Set iChart = Sheets(2).ChartObjects.Add(0, 0, iShape.Width, iShape.Height)
iChart.Chart.Paste
FileName = Application.GetSaveAsFilename(InitialFileName:="iPicture" & i, _
FileFilter:="JPEG文件(*.jpg),*.jpg", _
Title:="指定文件名")
If FileName = "False" Then GoTo Exit_Line '如果点击取消按钮则退出
iChart.Chart.Export FileName:=FileName, FilterName:=UCase(Right(FileName, 3)) '导出为图片文件
Exit_Line:
iChart.Delete
Next i '假设有三个,循环结束
End Sub
我使用的是Excel2016 (win7 64位)
|
|