Search notes:

Examples for VBScript MS-Office App Creator: Excel (add/replace module)

This is one of the examples for the command line Office App Creator.
The main purpose of this example is to demonstrate the function insertModule()
option explicit

sub main() ' {
    msgBox "This is version 1"
end sub ' }
Github repository VBS-MS-Office-App-Creator, path: /examples/Excel/add-module/functions-v1.bas
<job> <script language="VBScript" src="..\..\..\create-MS-Office-app.vbs" />

 <script language="VBScript">

   option explicit

   dim wshShell
   set wshShell = createObject("WScript.Shell")

   if wscript.arguments.count <> 1 then
      wscript.echo("Specify version of file to be inserted (1 or 2)")
      wscript.quit
   end if

   dim sourceVersion
   sourceVersion = wscript.arguments(0)

   if sourceVersion <> "1" and sourceVersion <> "2" then
      wscript.echo("Specify version of file to be inserted (1 or 2)")
      wscript.quit
   end if

   dim xls
   dim app

   dim xlsFileName
   xlsFileName = currentDir() & "created.xlsm"

   if sourceVersion = 1 then
      set xls = createOfficeApp("excel", xlsFileName)
      set app=xls.application
   else
      set xls = openOfficeApp("excel", xlsFileName)
      set app = xls.application
   end if

   app.visible = true

 '
 ' If sourceVersion = 2, insertModule replaces the module named func (because
 ' it already exists)
 '
   call insertModule(app, currentDir() & "functions-v" & sourceVersion & ".bas", "func", 1)

   app.run "main"

   xls.save

 </script>
</job>
Github repository VBS-MS-Office-App-Creator, path: /examples/Excel/add-module/run.wsf
c:…\> cscript run.wsf 1
option explicit

sub main() ' {
    msgBox "This is version 2"
end sub ' }
Github repository VBS-MS-Office-App-Creator, path: /examples/Excel/add-module/functions-v2.bas
c:…\> cscript run.wsf 2

See also

VBScript MS-Office App Creator

Index