I’m loading VBA code that has been extracted as files that are then added back to excel files on creation of a new instance of the file. These files are self contained classes, modules, forms, references,worksheets and the 'thisworkbook’components.
Here is my code which is contained inside a loop of the records telling me which items need to be added to this Excel file.
Select Case FileType.ToUpper
Case "MODULE", "FORM", "CLASS"
ExcelApp.VBE.ActiveVBProject.VBComponents.Import(PathName & FileName)
Case "REFERENCE"
ExcelApp.VBE.ActiveVBProject.References.AddFromFile(PathName & FileName)
Case "THISWORKBOOK"
ExcelApp.VBE.ActiveVBProject.VBComponents.Item("ThisWorkBook").CodeModule.AddFromFile(PathName & FileName)
Case "WORKSHEET"
'Worksheets must be added prior to any code modules, because once
'the code is added it tries to execute against the worksheets as
'you add them.
OriginalWorkBook = ExcelApp.WorkBook.Open(PathName & FileName)
OriginalWorkSheet = CType(OriginalWorkBook.Worksheets(AddinName), Worksheet)
OriginalWorkSheet.Copy(After:=WorkBook.Sheets(WorkBook.Worksheets.Count))
OriginalWorkBook.Close()
Case Else
'Do Nothing
End Select
All I can see that Aspose has is the ability to add a Module and for me to then add the code to the module. Please notice that each type of file takes a specific syntax to add it. Ignore the THISWORKBOOK because that is simply adding a sheet and I can do that.
Thanks.