none
Duplicate a Shape in Word 2013 from Access 2013 error RRS feed

  • Question

  • Error occurs on With oshp.duplicate  line.  From Access 2013 vba need to duplicate a shape in a Word 2013 document. 

    In a simple test document the With oshp.duplicate line works.  In the actual document that has been working fine using Office 2010 it causes an error on that line.

    Public Function SpecialTable_testDup()

    Dim shp As Word.Shape

    Dim oshp As Word.Shape

    Dim oshpRng As Word.shaperange

    Dim oshpcopy As Word.Shape

    Dim shpnum As Long

    Dim shptop As Long

    Dim shpleft As Long

    Dim shpID As Integer

    Dim i As Integer

    Dim ShapeIndex As Integer

    Dim mydoc As Word.Document

    Set mydoc = ActiveDocument

    mydoc.Activate

    'activate for good measure

    i = 1

    For Each shp In mydoc.Shapes           'kk

        If shp.Title = "chtGeoPieQ" Or shp.Title = "chtSegPiesQ" Then

            ShapeIndex = i

            shptop = shp.top

            shpleft = 0

            shpnum = shp.ID

            Debug.Print "mydoc.Shapes(i).ID = " & mydoc.Shapes(i).ID

            Exit For

        End If

        i = i + 1

    Next shp

      

    Set oshp = mydoc.Shapes(ShapeIndex)

        With oshp

            .top = shptop

            .Left = shpleft

            shpID = oshp.ID

            Debug.Print "oshp.name = " & oshp.name

       End With

      

    With oshp.Duplicate        'ERROR

        .name = "newshape1"

        .top = 200

        .Left = 100

        Debug.Print "mydoc.Shapes(newshape1).ID  = " & mydoc.Shapes("newshape1").ID

    End With

      

    End Function



    Kim Khan

    Monday, February 16, 2015 5:48 AM

All replies

  • Hello Kim

    I am moving your question to Word For Developer forum as this is the best forum for your question.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.


    Monday, February 16, 2015 6:06 AM
  • Hi kkhan7

    Could you please provide a sample document that exhibits the correct behavior in 2010, but not in 2013? Put it on OneDrive or a similar source so that we can download for testing (it's not possible to attach files to forum messages).


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 16, 2015 9:24 AM
    Moderator
  • Hi Kim,

    What’s the error message that you get?

    Regards

    Starain


    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.

    Tuesday, February 17, 2015 8:31 AM
    Moderator
  • Error occurs on With oshp.duplicate  line.  From Access 2013 vba need to duplicate a (pie chart) shape in a Word 2013 document.  Also I tried  Set oshpcopy = oshp.Duplicate line and received the same error that crashes Word 2013.
    Run-time error -2147023170.  Automation error.  The remote procedure call failed.

    Can I send the Word 2013 file via email to you?  Are there any none bugs regarding the duplicate command in Office 2013?

    Code starts:___________________________________

    Public Function testDup()

    Dim shp As Word.Shape

    Dim oshp As Word.Shape

    Dim oshpRng As Word.shaperange

    Dim oshpcopy As Word.Shape

    Dim shpnum As Long

    Dim shptop As Long

    Dim shpleft As Long

    Dim shpID As Integer

    Dim i As Integer

    Dim ShapeIndex As Integer

    Dim mydoc As Word.Document

    Set mydoc = ActiveDocument

    mydoc.Activate

     'activate for good measure

    ShapeIndex = 1

    i = 1

    For Each shp In mydoc.Shapes

    If shp.Title = "chtPieA" Or shp.Title = "chtPieB" Then

           ShapeIndex = i

           shptop = shp.top

           shpleft = 0

           shpnum = shp.ID

           Debug.Print "mydoc.Shapes(i).ID = " & mydoc.Shapes(i).ID

           Exit For

    End If

           i = i + 1

    Next shp

    Set oshp = mydoc.Shapes(ShapeIndex)

    With oshp

           .top = shptop

           .Left = shpleft

           shpID = oshp.ID

           Debug.Print "oshp.name = " & oshp.name

    End With

    Set oshpcopy = oshp.Duplicate 'error

    With oshpcopy

           .name = "newshape2"

           .top = 200

           .Left = 100

           Debug.Print "mydoc.Shapes(newshape1).ID = " & mydoc.Shapes("newshape1").ID

    End With

    With oshp.Duplicate 'ERROR

           .name = "newshape1"

           .top = 200

           .Left = 100

    Debug.Print "mydoc.Shapes(newshape1).ID = " & mydoc.Shapes("newshape1").ID

    End With

    Set oshp = Nothing

    Set oshpcopy = Nothing

    End Function


    Code ends:___________________________________


    Kim Khan


    Tuesday, February 17, 2015 10:44 PM
  • Run-time error -2147023170.  Automation error.  The remote procedure call failed.

    Kim Khan

    Thursday, February 19, 2015 6:59 PM
  • Hi,

    Please try it in other machine to check whether it has the same issue.

    Could you reproduce that issue in a sample file? If so, you could share this file on the OneDrive.

    Regards

    Starain


    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.

    Tuesday, February 24, 2015 2:33 AM
    Moderator
  • Thank you for your attention to this issue.   I am working with my team now to create a sample file that is uploadable.  Hopefully, this will be completed this week.

    -Kim



    Kim Khan

    Tuesday, February 24, 2015 4:06 PM
  • Thank you for your attention to this issue.   I am working with my team now to create a sample file that is uploadable.  Hopefully, this will be completed this week.

    -Kim


    Kim Khan

    Tuesday, February 24, 2015 4:07 PM
  • Hi,

    Please feel free to post the link here after finish the sample file.

    Regards

    Starain


    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, February 25, 2015 4:26 AM
    Moderator
  • Hi,

    Have you solved that issue? Anything update will be appreciated

    Regards

    Starain


    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.

    Monday, March 2, 2015 9:57 AM
    Moderator