FeResPost Web Site                     FeResPost Online User Manual

X.G.1.1 Programming the VBA-ruby bridge

The sources are made of three C++ “cpp” files, three C++ header files and one “def” file that defines the four functions that will be exported into the dll library. More precisely:

One remarks that the bridge between VBA and ruby implicitly assumes that the ruby “win32ole” extension is present. (This extension is required in the “RubyInit” method.) It was not a priori mandatory. However, the early loading of “win32ole” extension helps the programming of the for COM automation types translations. As the manipulation of these types by ruby programs might be necessary, it is necessary to load the extension as early as possible. This means that the ruby distribution with which the bridge is used must contain the “win32ole” extension. (Of course, the bridge should be used only on Windows platforms on which Office is installed.)

The compilation of the library is straightforward. On my computer, it looks like this:

    g++ -O2 -IC:/NewProgs/RUBY/Ruby187/lib/ruby/1.8/i386-mingw32 '  
        -c marshal.cpp  
    g++ -O2 -IC:/NewProgs/RUBY/Ruby187/lib/ruby/1.8/i386-mingw32 '  
        -c conversion.cpp  
    g++ -O2 -IC:/NewProgs/RUBY/Ruby187/lib/ruby/1.8/i386-mingw32 '  
        -c win32ole.cpp  
    gcc -O2 -LC:/NewProgs/RUBY/Ruby187/bin '  
        -fPIC -shared -static -m32 -Wl,--enable-auto-import '  
        marshal.o conversion.o win32ole.o -lmsvcrt-ruby18 '  
        -lws2_32 -luuid -lole32 -loleaut32 -lstdc++ -lm '  
        marshal.def -o vbaruby.dll

Note that the “vbaruby.dll” is linked to the “msvcrt-ruby18.dll” dynamic library. This means that the ruby runtime library is automatically loaded into excel when “vbaruby.dll” is loaded. This also means that “msvcrt-ruby18.dll” must be located in a directory defined in the “PATH” environment variable. Also, the “vbaruby.dll” library is linked to a particular version of ruby runtime library. If another version of ruby is installed, the bridge may have to be re-compiled.