I'm trying to write an excel add-in that automatically add predefined modules into the active workbook.
The "predefined modules" should meet the following two requirements:
- these modules are exported from excel vba editor, in the .bas format
- These .bas files shouldn't be visible to users.
after searching MSDN, I found this trick to do a similar thing:
void load_module(EXCEL.Workbook oBook){
VBIDE.VBComponent oModule;
oModule = oBook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule);
oModule.Name = "module_name";
sCode = "vba script content";
oModule.CodeModule.AddFromString(sCode);
//oModule.CodeModule.AddFromFile(file_name);
}
the "AddFromFile" method does work, but only when the file contains only vba codes and the file must be on the disk.
the problems are :
the .bas files generated by excel vba editor contains some "META" data in the first few lines, the previous methods will not parse these "META" data , and just output all the codes into a new module, which is not expected.
If we use the previous methods , the .bas files will be visible to users. But we need them to be INVISIBLE.
So, do you have any idea to solve this mess? : )