Search notes:

Examples for VBScript MS-Office App Creator: compileApp

This is an example that demonstrates the function compileApp of the VBScript MS-Office App Creator. This function compiles a VBA project and returns false if it has errors.

erroneous-module.vb

The following VBA module is erroneous: it contains an incorrect end function which should be end sub.
option explicit

sub main()

    dim txt as string
    txt = "Hello world"
    msgBox txt

end function ' should be "end sub", not "end function" !
Github repository VBS-MS-Office-App-Creator, path: /examples/compileApp/erroneous-module.vb

create-and-compile-app.wsf

create-and-compile-app.wsf uses the VBScript MS-Office App Creator to insert the above module and then compile the VBA project.
Because the module has an error, it reports it so to the command line. Note also that the VB Editor displays a message box that contains the error message.
<job>
<script language="VBScript" src="../../create-MS-Office-App.vbs" />
<script language="VBScript">
   option explicit

   dim app
   dim xls
   set xls = createOfficeApp("excel", currentDir() & "test-compilation.xlsm")

   if xls is nothing then ' {
      wscript.echo("Could not create excel worksheet.")
      wscript.quit(-1)
   end if ' }

   set app = xls.application

   insertModule app, currentDir() & "erroneous-module.vb", "errMod"  , 1

   if not compileApp(app) then
      wscript.echo("! compilation failed !")
   end if

   xls.save

   wscript.echo("The end")
   createObject("WScript.Shell").appActivate(app.caption)

</script> </job>
Github repository VBS-MS-Office-App-Creator, path: /examples/compileApp/create-and-compile-app.wsf

Index