excel - How to Call Subs from an Add-In Directly -


so it's easy write code call sub/function in add-in library via vba code, doing

call myfunctionorsub 

however, there way allow users directly call public subs in add-in? example, when user goes tools -> macros , pulls screen:

macro selection

i add list of macros in box subs included in add-ins linked file. is, have library (library.xlam) referenced current workbook. in library.xlam file, have subs (such copytoresults). want copytoresults appear runnable macro in list. there way that?

the solution come create sub in test file each sub in library.xlam. sub in test file nothing call library's sub. however, terrible purpose of having external libraries , terrible scalability, don't want go route.

  1. make form in xlam list box.
  2. use script post populate form. have change excel settings. get list of macros of module in excel, , call macros

here code form:

private sub btncancel_click()     unload me end sub  private sub btnexecute_click()      application.run "macros.xlam!" & lstmacros.value     unload me end sub   private sub userform_initialize()  dim pj vbproject dim vbcomp vbcomponent dim curmacro string, newmacro string dim x string dim y string dim macros string  on error resume next curmacro = "" documents.add  each pj in application.vbe.vbprojects       each vbcomp in pj.vbcomponents             if not vbcomp nothing                 if not vbcomp.codemodule = "utilities"                     = 1 vbcomp.codemodule.countoflines                        newmacro = vbcomp.codemodule.procofline(line:=i, _                           prockind:=vbext_pk_proc)                         if curmacro <> newmacro                           curmacro = newmacro                              if curmacro <> "" , curmacro <> "app_newdocument"                                 frmmacros.lstmacros.additem curmacro                             end if                         end if                     next                 end if             end if      next  next end sub 

in end mine looked this: macros form


Comments