none
(VS2017-VSTO) Word addin how insert new OLE Excel with x rows and x columns RRS feed

  • Question

  • Hi Community,

    I have found the way how I can edit an OLE Excel but not how I can insert a new one.

    Any hint?

     Sub DisplayInExcel()
            Dim oWordDoc As Word.Document
            oWordDoc = Globals.ThisAddIn.Application.ActiveDocument
            Dim oOLE As Excel.Workbook
            oOLE = Nothing
            Dim oSheet As Excel.Worksheet
            oSheet = Nothing
            Dim ils As Word.InlineShapes
            ils = oWordDoc.InlineShapes


            'oOLE.Application.Workbooks.Add(1)
            ils(1).OLEFormat.Activate()
            oOLE = ils(1).OLEFormat.Object


            oSheet = oOLE.Worksheets(1)
            oSheet.Range("A1").Value = " YES"

        End Sub
    End Class

    Greeting from Bavaria,

    Bitfox

    Tuesday, May 23, 2017 2:14 PM

Answers

  • Hi Bitfox,

    I try to search regarding setting the rows and columns.

    but I did not get anything useful in this direction.

    also InlineShapes.AddOLEObject method  does not provide any option for it.

    you can try to set height and width of shape but I think it will not fulfill your requirement.

    other work around is to activate the ole object in editing mode and then manually resize it with mouse.

    Regards

    Deepak


    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. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Bitfox Tuesday, May 30, 2017 1:17 AM
    Thursday, May 25, 2017 9:26 AM
    Moderator

All replies

  • Hi Bitfox,

    you can refer code below to add OLE Object with VSTO.

    Private Sub ThisAddIn_Startup() Handles Me.Startup
    
    
    
            Dim wdApp As New wd.Application
    
            Dim wdDoc As wd.Document = wdApp.Documents.Add()
    
            wdApp.Visible = True
    
            Dim ClassType As Object = "Excel.Sheet.1"
    
            Dim FileName As Object = "C:\Users\v-padee\Desktop\Book4.xlsx"
    
            Dim LinkToFile As Object = False
    
            wdDoc.InlineShapes.AddOLEObject(ClassType, FileName, LinkToFile)
    
        End Sub

    Output:

    Reference:

    InlineShapes.AddOLEObject method

    you can modify the code as per your requirement.

    Regards

    Deepak


    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. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 24, 2017 6:25 AM
    Moderator
  • Hi Deepak,

    thank you very much  for for answer. Mine wile I also found the InlineShape AddOLEObject - but I not able till now to insert this object with x Rows and Y columns. My bee you have for this also an hint?

    Best regards,

    Bitfox 


    • Edited by Bitfox Wednesday, May 24, 2017 6:13 PM
    Wednesday, May 24, 2017 6:03 PM
  • Hi Bitfox,

    I try to search regarding setting the rows and columns.

    but I did not get anything useful in this direction.

    also InlineShapes.AddOLEObject method  does not provide any option for it.

    you can try to set height and width of shape but I think it will not fulfill your requirement.

    other work around is to activate the ole object in editing mode and then manually resize it with mouse.

    Regards

    Deepak


    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. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Bitfox Tuesday, May 30, 2017 1:17 AM
    Thursday, May 25, 2017 9:26 AM
    Moderator
  • Hi Deepak,

    thx for your answer.
    Is it also not possible to access the worksheet proprieties of the InlineShapes. If it possible I can use the Columns("E:W").EntireColumn.Hidden = True.

    Thanks in advance,
    Bitfox.


    Thursday, May 25, 2017 11:44 AM