将图表转换为图片powerpoint

时间:2018-02-26 03:56:34

标签: vba converter powerpoint

我通常使用这一次将图表转换为PPT中的图像。但是这一次,在运行此代码时,它显示“错误242,需要主题”

任何VBA大师都可以帮我修复它吗?

这里是代码:

 `Sub EnumChartsInPresentation()
Dim sld As Slide
Dim shp As Shape
Dim ctr As Long
For Each sld In ActivePresentation.Slides
    For ctr = sld.Shapes.Count To 1 Step -1
        If GetShapeType(sld.Shapes(ctr)) = msoChart Then
            Call ConvertChartToImage(sld, sld.Shapes(ctr))
        End If
    Next
Next
End Sub

Function GetShapeType(shp As Shape) As MsoShapeType
If shp.Type = msoPlaceholder Then
    If shp.PlaceholderFormat.ContainedType = msoChart Then
        GetShapeType = msoChart
        Exit Function
    End If
End If
GetShapeType = shp.Type
End Function

Sub ConvertChartToImage(sld As Slide, shp As Shape)
Dim shpChartImage As Object
shp.Copy
DoEvents
Set shpChartImage = sld.Shapes.PasteSpecial(ppPastePNG)
With shpChartImage
    .Left = shp.Left
    .Top = shp.Top

    Do While shp.ZOrderPosition < shpChartImage.ZOrderPosition
        Call shpChartImage.ZOrder(msoSendBackward)
    Loop

    shp.Visible = False
    'shp.Delete
    'Set shp = Nothing
End With
End Sub`

0 个答案:

没有答案