Using Regasm.exe

If you work through the process described in the previous post Visual Studio will create two files (ALMatrixLib.tlb and ALMatrixLib.dll) that will automatically be registered so that the Excel VBA routines will be able to use them.  On the other hand if you copy these two files from the download file to your Windows\System32 folder you will find that the Excel User Defined Functions (UDFs) return an error.

In order to get these functions working it is necessary to register the .dll and .tlb files using a program called Regasm.exe.  This is described in the “Deployment” section of A Beginner’s Guide to calling a .NET Library from Excel, but that guide appears to have been written in the days before Windows Vista and Windows 7, and the added security features in these versions make the procedure significantly more difficult.  The following three sections give step-by-step instructions for this procedure, depending on whether you have Visual Studio Express installed (easiest); you have a file manager with a command line installed, such as Total Commander (also pretty easy); or you have to use the built in Windows tools (not so easy).  In each case you need to run the Regasm program from the command line “as administrator”.

If you have Microsoft Visual Studio installed:

  • Click on the Windows “Start” Button (bottom left)
  • Click on “All Programs”
  • Click on Microsoft Visual Studio
  • Right click on Visual Studio Command Prompt
  • Select “Run as Administrator”
  • After clicking the confirmation box you should get a Command Prompt window as shown below
  • Enter (with the path amended as required) : regasm /codebase C:\Windows\System32\ALMatrixLib.dll /tlb
  • Close the Command Prompt Window; that’s all

Visual Studio Command Prompt

If you have Total Commander (or similar) installed:

  •  Right click on the Total Commander Icon and select “Run as Administrator”
  • Navigate to the Windows\Microsoft.NET\Framework\v4.0.30319\ folder (or the latest version installed on your machine)
  • In the Total Commander Command Line enter: cmd
  • In the command prompt window that appears enter:  (with the path amended as required) : regasm /codebase C:\Windows\System32\ALMatrixLib.dll /tlb
  • Close the Command Prompt Window; that’s all

Total Commander with cmd command

Using only Windows built in tools:

  • Open the “Computer” window and navigate to C:\Windows\Microsoft.NET\Framework\v4.0.30319 (or the latest version on your computer)
  • Right click on the final folder name and select “copy as text”
  • Click on the Windows “Start” Button (bottom left)
  • Enter cmd in the search box
  • Right click on the cmd icon under Programs(1) and select Run as Administrator
  • It is necesary to move to the folder containing the Regasm.exe file.  In the command line window enter:
    CD C:\Windows\Microsoft.NET\Framework\v4.0.30319
    or enter CD , right click and paste the folder path name
  • Ensure that you are in the correct folder then enter:
    regasm /codebase C:\Windows\System32\ALMatrixLib.dll /tlb (with path amended as required)
  • Close the command prompt window

Moving to the .Net\Framework folder from the command line

After completing this procedure the Alglib functions in the Excel file should find the necessary dll files and work without a problem.  If not, try:

  • In the Visual Basic Editor, check that ALMatrixLib is listed as a reference under Tools-references.
  • If it isn’t, click browse and select the file ALMatrixLib.tlb
  • If it is, deselect it, close the references window, re-open it and click browse and select ALMatrixLib.tlb

Any problems remaining after all that, please let me know.

This entry was posted in Excel, Link to dll, UDFs, VBA and tagged , , , , , . Bookmark the permalink.

3 Responses to Using Regasm.exe

  1. Pingback: Frame4; now with added Alglib | Newton Excel Bach, not (just) an Excel Blog

  2. Pingback: Installing dlls on 64 bit Windows | Newton Excel Bach, not (just) an Excel Blog

  3. Pingback: Daily Download 5: Frame Analysis | Newton Excel Bach, not (just) an Excel Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s