Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何从Powerpoint中将表格(形状)导出为JPG_Vba_Powerpoint - Fatal编程技术网

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

Vba 如何从Powerpoint中将表格(形状)导出为JPG,vba,powerpoint,Vba,Powerpoint,我可以从Powerpoint中将图表导出为JPG文件,但无法使用表格来实现这一点,据我所知,表格仍然是一个可以导出的“形状” 这是我用来将图表导出为JPG的代码的清理版本 Const imgFilePath as String = "ChartImage.JPG" Sub ExportChartJPG() Dim cht as Variant 'this will hold the Chart/Shape object Set cht = ActivePresentation.Slides(

我可以从Powerpoint中将图表导出为JPG文件,但无法使用表格来实现这一点,据我所知,表格仍然是一个可以导出的“形状”

这是我用来将图表导出为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
我认为这很容易修改,比如:

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
但这会引发错误
13
不匹配


我也尝试过将
cht
作为一个形状而不是变体,并设置
cht=ActivePresentation.Slides(1)。形状(“Table1”)
,也没有成功。

我有一个非常奇怪的想法。查看第一部分保存图表和第二部分保存表格的代码

Sub ExportinChartAndTable()
Dim imgFilePath As String
    imgFilePath = ActivePresentation.Path & "\chart"

Dim shp As Shape
    Set shp = ActivePresentation.Slides(1).Shapes(1)
Dim shpChart As Chart
    Set shpChart = shp.Chart
'exporting chart
On Error Resume Next
    Kill imgFilePath
On Error GoTo 0
shpChart.Export imgFilePath & "chart.jpg", "JPG"

Stop
Dim chartPart As ChartData
    Set chartPart = shpChart.ChartData

imgFilePath = ActivePresentation.Path & "\dataTable.jpg"

chartPart.Workbook.worksheets("arkusz1").Range("a1:c20").Copy
shpChart.Paste
shpChart.Shapes(1).Width = shp.Width
shpChart.Shapes(1).Height = shp.Height
On Error Resume Next
    Kill imgFilePath
On Error GoTo 0
shpChart.Export imgFilePath, "JPG"


End Sub
你必须想出办法来检查桌子的范围。我希望
CurrentRegion
能起作用,但事实并非如此。您可以使用这种可能性来计算表中的行数和列数(这是可能的)。或者你有固定的射程,所以这很容易。还有一件事,调整表的大小时,必须调整维度

根据David comment进行编辑。我保留了上述解决方案,以便对其他人有用(请参考下面的评论)


这一点基于相同的逻辑。将表格复制到可以导出的图表中(这是唯一一种形状)。

虽然KazJaw的解决方案可行,但有点麻烦(复制需要额外的时间来处理,我认为是因为没有“等待”足够长的时间来完成复制、剪贴板问题等原因导致了错误。)

我打开对象浏览器,右键单击并显示隐藏方法,现在可以在
形状上使用
导出
方法

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
子导出shapejpg()
Dim cht as Variant'这将保存图表/形状对象

Set cht=ActivePresentation.Slides(1).Shapes(“Table1”)'您提供的解决方案是针对Excel的-我认为如果需要,我很可能在Excel中执行此操作,但我的问题是在Powerpoint中,表格是作为幻灯片中的形状创建的,所以我不能使用此选项。好的,我以为您想要获取制作图表的数据。不,在这种情况下没有图表,只是PPT幻灯片上的表对象,而不是Excel工作簿中的表对象。我正在开发的应用程序的一部分也会在PPT中创建图表,我可以将图表导出为JPG,但到目前为止还没有找到导出表格形状的方法。因此,请参见上面答案中的第二个想法谢谢KazJaw。这是解决这个问题的一种创造性方法。这不是一个完美的解决方案,但目前正在发挥作用。我会看看是否能找到更好的方法,但如果不能,我会接受你的答案。通过简单阅读PDF,我认为我可以传递一些额外的参数来重新调整导出图像的大小,但现在,这肯定是我希望找到的方法。
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