none
Embedded excel table conversion not working in Interop.Word RRS feed

  • Question

  • HI Team,

       I had convert the word embedded excel tables conversion using

      ActiveDoc.Shapes[0].ConvertToInlineShape();

    It is working fine but, in middle the word is crashing and getting error message like

    Error popup: Microsoft word is not working.(restart,cacel,..)

    Could you suggest to avoid word crashing while converting excel tables.

    Regards,

    Kiran R L


    R L Kiran

    Friday, November 30, 2018 11:26 AM

All replies

  • Hi Kiran,

    Please use the following code:

    Sub ConvertXLObjs()
    Dim i As Long, Rng As Range
    Dim objOLE As Word.OLEFormat, objXL As Object
    With ActiveDocument
      For i = .InlineShapes.Count To 1 Step -1
        With .InlineShapes(i)
          If Not .OLEFormat Is Nothing Then
            If Split(.OLEFormat.ClassType, ".")(0) = "Excel" Then
              Set Rng = .Range
              Set objOLE = .OLEFormat
              objOLE.Activate
              Set objXL = objOLE.Object
              objXL.Worksheets(1).UsedRange.CurrentRegion.Copy
              objXL.Application.Undo
              .Delete
              Rng.PasteAndFormat wdTableInsertAsRows
            End If
          End If
        End With
      Next
    End With
    Set objXL = Nothing: Set objXL = Nothing: Set Rng = Nothing
    End Sub

    For more information, please see the following links:

    How to convert all embeded excel sheets in word into word's tables

    How to convert embedded excel sheet to word table?

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Saturday, December 1, 2018 1:03 AM
  • Hi Kiran,

     

    Thanks for your asking. Please remember to mark the replies as answers if they helped and please help us close the thread.

     

    Thank you for understanding. If you have any question, or update, please feel free to let us know.

     

    I wish you a happy life!

     

    Best Regards,

     

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Tuesday, December 4, 2018 3:11 AM