Search notes:

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

This is an example that uses the command line VBScript Office App Creator to create an Excel Workbook that has a workbook_open() function which will be executed when the Workbook is opened.

thisWorkbook.vb

This is the VBA module that will be inserted into the Workbook that will be created.
The workbook_open() sub calls msgBox() to demonstrate that it has worked.
option explicit

sub workbook_open() ' {

    msgBox "Workbook was opened"

end sub ' }
Github repository VBS-MS-Office-App-Creator, path: /examples/Excel/workbook_open/thisWorkbook.vb

create.wsf

create.wsf is the script that creates the Excel workbook (createOfficeApp(…) and inserts thisWorkbook.vb (replaceThisWorkbookModule(…)).
<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")
   set app = xls.application

   call replaceThisWorkbookModule(app, currentDir() & "thisWorkbook.vb")

   xls.save

   wscript.echo("The end")

</script> </job>
Github repository VBS-MS-Office-App-Creator, path: /examples/Excel/workbook_open/create.wsf
This script needs to be started on the command line (cmd.exe, PowerShell) like so;
P:\ath\to\dir\> cscript create.wsf

Macros have been disabled

Chances are that macros need to be explicitly enabled when the workbook is run. This is indicated by the following warning-message:
It might be possible to add the document to the trusted location with this PowerShell script.

See also

VBScript MS-Office App Creator

Index