Question

Bitfox on Tue, 23 May 2017 14:14:45


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


Sponsored



Replies

Deepak Saradkumar Panchal on Wed, 24 May 2017 06:25:24


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

Bitfox on Wed, 24 May 2017 18:03:49


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 


Deepak Saradkumar Panchal on Thu, 25 May 2017 09:26:03


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

Bitfox on Thu, 25 May 2017 11:44:30


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.