Thank you very much! Now it works!
The Load method is a static method on Workbook which returns the loaded Workbook instead. It is not an instance method, even though VB allows you to call it as if it were. Basically, the loaded workbook is being returned from Load and then getting thrown away because you are not storing it. Try using this code instead.
Dim ExcelTemplate As String = Application.StartupPath & "\Export_Template.xlsm" Dim theWorkBook = Infragistics.Documents.Excel.Workbook.Load(ExcelTemplate) ExcelExporter.Export(Grid, theWorkBook) theWorkBook.Save(Application.StartupPath & "\Test.xlsm")
Hello,
I tried the same. But when I save the workbook to the file system there is no macro in it.I am doing the things described one post above followed by one line of code more:
Dim theWorkBook As New Infragistics.Documents.Excel.Workbook Dim ExcelTemplate As String = Application.StartupPath & "\Export_Template.xlsm" theWorkBook.Load(ExcelTemplate)
ExcelExporter.Export(Grid, theWorkBook) theWorkBook.Save(Application.StartupPath & "\Test.xlsm")
I tried this by using the xlsm and the xls extension. In both cases there is no macro in it. But my template contains a macro.What is wrong?
Round-trip support means if you load in a workbook which has VBA code, modify that workbook, and save it out again, that code will not be lost. However, you cannot change or add to that code. So I guess you could have a blank workbook with your code in it and load that workbook. Then call the overload of Export which takes a Workbook instance and pass in your loaded workbook. Then the exported workbook will have the code in it when you save it out.