Hi all,
Can I create a new workbook/worksheet at run time just like the code below using VSTO components.
Thanks.
sample code:
________________________________________
Imports
Microsoft.OfficeImports
Microsoft.Office.CoreSub()
Dim xlApp As New Excel.Application
Dim excelBook As Excel.Workbook = xlApp.Workbooks.Add
Dim xlSheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
......
......
......
xlApp .visible=true
end sub

Convert to VSTO - (EXCEL)
DoRsal
You need to import
Imports
Microsoft.Office.Tools.ExcelImports
Microsoft.Office.Interop.Excelamm.firas
do u have a sample code
to instantiate the classes of a workbook/worksheet like the code above.
Thanks
Stein
Hi,
I'm sorry to say that this scenario currently is not supported. Microsoft.Office.Tools.Excel.Worksheet is a wrapper class that VSTO creates to support coding behind the document. Excel knows nothing about it, so adding a new worksheet at runtime would not result in a new wrapper class instance being created. Also, even if Excel did create a new wrapper instance, it is a completely different object so that cast would not work.
It would be technically possible for you to do this work yourself and enable the scenario, but I would discourage you from doing it because you would be relying on undocumented methods which are likely to change in the future (and would therefore break your solution going forward).
Sincerely,
Geoff Darst
Microsoft VSTO Team