none
VSTO - PowerPoint (All charts to EMF) - Exception from HRESULT: 0x800A01A8 RRS feed

  • Question

  • Hi,

    I created a vsto PowerPoint 2007 addin for converting PowerPoint charts into EMF images in all the slides.
    it was running fine in office 2007 version.

    But in office 2013 version, it gave the following error.
    Exception from HRESULT: 0x800A01A8

    For nearly two days, I have been trying to solve this.
    Please help me.

    Here is the code:

        Public Sub PasteAsEMF()
            Dim sld As PowerPoint.Slide
            Dim shp As PowerPoint.Shape
            Dim oshpasted As Object

            Dim chartcount As Short = 0

            Dim left1 As Single
            Dim top1 As Single

            Try
                sResponse = MsgBox("PPT 2007 Charts will be pasted as EMF...", vbOKCancel, "Charts to EMF")
                If sResponse = vbOK Then

                    UngroupIfChartIsFoundInGroup()

                    For Each sld In Me.Application.ActivePresentation.Slides
                        'Me.Application.ActiveWindow.View.GotoSlide(sld.SlideIndex)
                        'sld.Select()
                        For Each shp In sld.Shapes
                            'shp.Select()
                            If shp.Type = Microsoft.Office.Core.MsoShapeType.msoChart Then
                                chartcount = chartcount + 1
                                With shp
                                    left1 = .Left
                                    top1 = .Top
                                End With

                                shp.Copy()
                                oshpasted = sld.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteEnhancedMetafile)
                                With oshpasted
                                    .Left = left1
                                    .Top = top1
                                End With
                                Do While shp.ZOrderPosition < oshpasted.ZOrderPosition
                                    oshpasted.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward)
                                Loop
                                shp.Delete()
                                Runtime.InteropServices.Marshal.ReleaseComObject(shp)
                                Runtime.InteropServices.Marshal.ReleaseComObject(oshpasted)

                            ElseIf shp.Type = Microsoft.Office.Core.MsoShapeType.msoPlaceholder Then
                                If shp.PlaceholderFormat.ContainedType = Microsoft.Office.Core.MsoShapeType.msoChart Then
                                    chartcount = chartcount + 1
                                    With shp
                                        left1 = .Left
                                        top1 = .Top
                                    End With

                                    shp.Copy()
                                    oshpasted = sld.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteEnhancedMetafile)
                                    With oshpasted
                                        .Left = left1
                                        .Top = top1
                                    End With
                                    Do While shp.ZOrderPosition < oshpasted.ZOrderPosition
                                        oshpasted.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward)
                                    Loop

                                    shp.Delete()
                                    Runtime.InteropServices.Marshal.ReleaseComObject(shp)
                                    Runtime.InteropServices.Marshal.ReleaseComObject(oshpasted)

                                End If
                            End If
                        Next shp
                    Next sld
                    GC.Collect()
                    GC.WaitForPendingFinalizers()

                    DeleteEmptyPlaceholders()

                    If chartcount = 0 Then
                        MsgBox("No charts were found in this presentation...", vbInformation)
                    Else
                        MsgBox(chartcount & " charts converted to EMF's...", vbInformation)
                    End If

                    'ElseIf sResponse = vbCancel Then
                    '    MsgBox("Process cancelled...", vbInformation)
                    '    Exit Sub
                Else
                    MsgBox("Process cancelled...", vbInformation)
                    Exit Sub
                End If

            Catch ex As Exception
                MsgBox(ex.Message, vbCritical)
            End Try
        End Sub


    Thanks for your great help.

    Regards,
    balumail75.

    Thursday, June 11, 2015 1:14 PM

All replies

  • Hi,

    I have tested the code you provided, it could successfully work in Office 2007, and same error shows in Office 2013. Since this is a complex issue, I will involve more engineers in this case to help you on this case.

    At mean time ,as temporary workaround, you may justify the position by the following code .

    Public Sub PasteAsEMF() Dim sld As PowerPoint.Slide Dim shp As PowerPoint.Shape Dim chartcount As Short = 0 Dim left1 As Single Dim top1 As Single For Each sld In Me.Application.ActivePresentation.Slides 'Me.Application.ActiveWindow.View.GotoSlide(sld.SlideIndex) 'sld.Select() For Each shp In sld.Shapes 'shp.Select() If shp.Type = Microsoft.Office.Core.MsoShapeType.msoChart Then chartcount = chartcount + 1 With shp left1 = .Left top1 = .Top End With

    'Copy and delete the chart fist,then justify the position by the shape's property shp.Copy() shp.Delete()

    sld.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteEnhancedMetafile) With sld.Shapes(1) .Left = left1 .Top = top1 End With End If Next shp Next sld End Suber


    Thanks for your understanding.

    Best Regards,

    Lan



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 12, 2015 5:32 PM
    Moderator
  • Hi Lan,

    With reference to your code, Can the reference be set to the pasted shape,
    b'cos I am using for setting the shape's zorderposition in my code.
    The code is there, in my pasted code.

    Thanks for your great help.

    Regards,
    Balumail75.


    Thursday, June 18, 2015 2:31 PM
  • Hi,

    In the code above , it has using Shape(index) to find the pasted shape. And also, you could set the shape's zorderposition for the shape.

     sld.Shapes(1).ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward)

    Hope this could help you.

    Best Regards,

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, June 24, 2015 5:35 AM
    Moderator