Here are the instructions for an example that works with Windows 10, Word 2016, and xojo 2019 Release 3.1:
Create a new Excel program and do something like add 1 and 1 for an answer of 2, and save the file on the desktop of your computer with the filename Test1.xlsx.
Create a desktop program in Xojo and add a button. In the button create an action event and add the following code:
[code]Sub Action() Handles Action
Dim Word as New WordApplication
Word.Documents.Add
Word.Visible = True
Word.Selection.InlineShapes.AddOLEObject(“Excel.Sheet.12”,“C:\Users\eugen\Desktop\Test1.xlsx”, False, False)
End Sub
[/code]
This worked on Microsoft Word that is installed on my computer. I am not sure if it works with Office 365 that is running in the cloud.
i get only an icon with the embedded Excel sheet in my document. That’s what I need, because the Excel sheet may contain many, many columns and rows - too much for a Word document.
Now I am looking for the green icon with the Excel symbol. Actual I get an icon with an empty page like the GenericDocumentIcon in macOS.
The last question for me is: Do I always have to first create an Excel file on the hard drive before embedding it in the Word file? Or is that also possible directly from the Excel object?
Hi Michael, I am glad that the solution is working for you.
It appears that the AddOLEObject requires a file path and name, which means it looks like a file is needed. I am not sure if the file must be located on your computer or from a public file system on the internet with an https:// prefix?
I am not sure what is means by directly from the Excel object, could you help me understand your question a little more? Thanks.
var oExcel as new ExcelApplication
var oBook as ExcelWorkbook
oExcel.Visible = true
oBook = oExcel.Workbooks.add
oExcel.Application.DisplayAlerts = false
<...fill the cells with values...>
oBook.SaveAs( <Path of ExcelSheet><Excel file.XLSX> )
// Quit Excel
oExcel.Application.DisplayAlerts = true
oExcel.Application.Quit
but I like to embed the Excel file without the “SaveAs” and use maybe the oBook object for embedding. So I can save the transfer to the hard drive and the deletion of the temporary file afterwards.
I tried a few modifications to the program, and I could only get the program to embed Excel in Word with a saved file. There might be a workaround, and for now it looks like the program needs an Excel file and then embed the file in Word.
This property can be used to hide an office application while working. It is useful so that a user becomes not confused from busy Excel windows while a table is created or other tasks are performed.