Search notes:

Examples for VBScript MS-Office App Creator: Excel (simple)

This is one of the examples for the command line Office App Creator.
Its main purpose is to demonstrate the functions createOfficeApp() and insertModule().
On the command line (console), this example must be run by executing
C:\> cscript create.wsf
When executed, create.wsf calls createOfficeApp() to create a Excel Workbook, named created.xlsm and then calls insertModule() to add a VBA module to the workbook.
With the module now added, the script executes application.run(…) to call the VBA sub main which is defined in the module that just was inserted.
xls.save saves the newly created workbook.
Finally, appActivate is used to bring the Excel application to the front.

functions.bas

functions.bas is the module that is inserted with insertModule(). It contains the sub main which is called from the create.wsf script.
option explicit

sub main(projectRootDir as variant) ' {
  '
  ' Note: the parameter(s) need to be declared as variant
  '       in Excel (apparently not so in Access).
  '
    activeSheet.cells(1,1) = "projectRootDir = " & projectRootDir

end sub ' }
Github repository VBS-MS-Office-App-Creator, path: /examples/Excel/simple/functions.bas

create.wsf

create.wsf is the script that uses the VBS App Creator to create the workbook:
<job>
<script language="VBScript" src="..\..\..\create-MS-Office-app.vbs" />
<script language="VBScript">

   option explicit

   dim app
   dim xls
   set xls = createOfficeApp("excel", currentDir() & "created.xlsm")
   if xls is nothing then ' {
      wscript.echo("Could not create excel worksheet.")
      wscript.quit(-1)
   end if ' }

   set app = xls.application

   call insertModule(app, currentDir() & "functions.bas", "funcs", 1)

   call app.run("main", currentDir())

   xls.save

   wscript.echo("The end")

 '
 ' Bring created Excel Workbook to the front:
 '
   createObject("WScript.Shell").appActivate(app.caption)

</script> </job>
Github repository VBS-MS-Office-App-Creator, path: /examples/Excel/simple/create.wsf

See also

VBScript MS-Office App Creator

Index