如何从Powerpoint将表(形状)导出为JPG

Dav*_*ens 3 powerpoint vba powerpoint-vba

我可以将图表作为JPG文件从Powerpoint导出,但是无法使用表格进行处理,据我所知,这仍然是一个应该能够导出的"形状".

这是我用于将图表导出为JPG的代码的清理版本.

Const imgFilePath as String = "ChartImage.JPG"
Sub ExportChartJPG()
Dim cht as Variant  'this will hold the Chart/Shape object

Set cht = ActivePresentation.Slides(1).Shapes("Chart1").Chart

On Error Resume Next
    Kill imgPath
On Error GoTo 0

cht.Export imgPath, "JPG"

End Sub
Run Code Online (Sandbox Code Playgroud)

我认为这很容易修改,如:

Sub ExportChartJPG()
Dim cht as Variant  'this will hold the Chart/Shape object

Set cht = ActivePresentation.Slides(1).Shapes("Table1").Table

On Error Resume Next
    Kill imgPath
On Error GoTo 0

cht.Export imgPath, "JPG"

End Sub
Run Code Online (Sandbox Code Playgroud)

但这是错误的错误13.

我也尝试将尺寸设计cht为Shape而不是Variant,并且设置cht = ActivePresentation.Slides(1).Shapes("Table1")也不成功.

Dav*_*ens 5

虽然KazJaw的解决方案有效,但它有点麻烦(复制需要额外的时间来处理,我认为由于没有"等待"足够长的时间来完成复制,剪贴板问题,我得到了错误等等)

http://www.tech-archive.net/pdf/Archive/Office/microsoft.public.office.developer.vba/2006-10/msg00046.pdf

我打开对象浏览器,右键单击,然后显示隐藏的方法,现在允许我Export在a上使用该方法Shape.

Sub ExportShapeJPG()
Dim cht as Variant  'this will hold the Chart/Shape object

Set cht = ActivePresentation.Slides(1).Shapes("Table1") '<-- removed .Table and only pass the Shape itself

'Likewise, for charts, omit the .Chart:
' Set cht = ActivePresentation.Slides(1).Shapes("Chart1") 


On Error Resume Next
    Kill imgPath
On Error GoTo 0

cht.Export imgPath, ppShapeFormatJPG  '<-- The export syntax is slightly different using ppShapeFormatJPG instead of "JPG"

End Sub
Run Code Online (Sandbox Code Playgroud)