given workbook MyTestWorkbook.xls needs some dynamic functionality.
If the PFE is installed then such functionality may be provided by placing a
Python script file MyTestWorkbook.pfe into the same directory.
Note that the script file MyTestWorkbook.pfe has the same name and the "pfe"
If the Excel application opens the MyTestWorkbook.xls then the Python for
Excel would execute the MyTestWorkbook.pfe. The execution would happen
in-process with Excel. The vba module and the predefined objects Application
and ExcelListener would be accessible in the script. The script might allocate
some global variables, alter contents of the workbook and install event
handlers. Such organization permits imposing arbitrary functionality on the
workbook. It also closely resembles the VBA for Excel's way of controlling the
If the "pfe" scripts does not allow any exceptions to propagate to the highest
Python level then the ControlShell does not have to activate. However, it does
pop up in the event of exception. At that moment the pdb module is already
imported. Hence, the user may switch to the add-in shell and execute the
command "pdb.pm()" to start the postmortem debugging. If the programmer wishes
to override such behavior then the sys.stderr should be replaced.
All local variables allocated in the "pfe" script disappear after the pfe
script finishes. The programmer may use the "global" keyword to hold the data
that should persist after the script finishes. The "import" directives should
be placed inside function bodies.