0

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:

  1. these modules are exported from excel vba editor, in the .bas format
  2. 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 :

  1. 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.

  2. 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? : )

lowatt
  • 363
  • 2
  • 18

1 Answers1

0

I would do the follow:

  1. Copy files from network location onto local disk.
  2. Remove the unwanted "META" data from the files.
  3. Load into Excel.
  4. Delete local copies from disk.

Of course, the files on the network would be accessible to them as well, but it should be harder for them to find.

Craig T
  • 2,761
  • 5
  • 25
  • 33
  • Those META data are useful. For example, the "CLASS" meta just defines whether this is a class define or a module define. – lowatt Oct 15 '12 at 12:14