FeResPost Web Site                     FeResPost Online User Manual

X.G.2.4 Other tips

In the “ThisWorkbook” VBA code, two excel event subroutines are provided. When opening, the event “Workbook_Open” changes the excel execution directory to the directory containing the workbook, loads the vbaruby bridge library and initializes ruby by calling “libInit”, then calls the “PostProject::DbAndLoadCases::setWorkbook” method to initialize the corresponding variable of the ruby post-processing program:

    Sub Workbook_Open()  
        ChDrive (Left(ActiveWorkbook.Path, 1))  
        ChDir (ActiveWorkbook.Path)  
        Application.Calculation = xlCalculationAutomatic  
        Call libInit  
        Dim x As Variant  
        x = CallMethod("PostProject::DbAndLoadCases", "setWorkbook", ThisWorkbook)  
End Sub

This step is mandatory if one wants the “main.rb” file to be loaded correctly, because a path relative to the directory containing “PostProject.xlsm” is used in the “RubyMarshal” VBA module. (Sees section X.G.2.2.) It also ensures that the “main.log” file to which ruby standard output is redirected is located in the same directory as “PostProject.xlsm”. (See section X.G.2.1.)

When closing the excel workbook, the following method is called:

    Sub workbook_BeforeClose(cancel As Boolean)  
        Application.Calculation = xlCalculationAutomatic  
        Dim x As Variant  
        x = CallMethodValue("PostProject", "clearModuleVariables")  
   End Sub

This method is meant, among other things, to remove all references to excel automation objects, so that the closing of the application is cleanly done. Practically, it sometimes fail, so that you have to kill excel with the task manager. (If someone can explain me why...)