I’m using Aspose.Cells for .NET 184.108.40.206
I have a workbook with some macros in it, they are:
-ThisWorkbook which does things when the file opens
-Module1 - Holds some code
-frmGui - A gui form (designer) with code behind
I’m trying to get Aspose.Cells to copy the VBA (and the form) from one workbook to another. The key bit of my code is
'add any macros from the template workbook For Each vbaItem As Vba.VbaModule In tp.VbaProject.Modules If vbaItem.Name = "ThisWorkbook" Then wb.VbaProject.Modules("ThisWorkbook").Codes = vbaItem.Codes ElseIf vbaItem.Codes Like "*'[AUTO COPY TO TARGET]*" Then Debug.Print(vbaItem.Name) Dim vbaMod As Integer vbaMod = wb.VbaProject.Modules.Add(vbaItem.Type, vbaItem.Name) wb.VbaProject.Modules(vbaMod).Codes = vbaItem.Codes End If Next
where tp is the workbook with the macros, and wb is the workbook where i want to copy them.
All the relevant segments of code are triggering however if I copy the code for the form (designer), Once i save the file and try to open it Excel claims the workbook is corrupt and needs repairing. If you say Yes it comes back with “Removed Part: /xl/vbaProject.bin part.”
Any thoughts on how I can resolve this issue.