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.

7 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

  4. Jonrizz Torres says:

    i did try to do all the instructions mentions above, i also see the new library on the excel reference but when i am creating new object using vba i as not able to do it. can you please help me why?

    thanks
    Jonrizz

    Like

    • dougaj4 says:

      I just happen to be trying to run some of the Alglib routines on a new computer (which doesn’t have Visual Studio at the moment), and I am also having some problems, so I hope we can help each other. I am running 64 bit Windows and 32 bit Excel, so comments below may not be applicable if you have a different setup.

      The first problem I had using Regasm was that the library did not appear when I browsed from the VBE “add reference” window. The solution to that problem is given at:
      https://newtonexcelbach.wordpress.com/2013/03/28/installing-dlls-on-64-bit-windows/
      which worked for me. But you have successfully created the reference in the VBE, so that’s not your problem.
      Having created the links to two Alglib dlls I found that one worked, but the ALMatrixLib.dll file required for the frame analysis spreadsheet still didn’t work. I am still working on that, and will post here if/when I find a solution.

      Could you provide more details of what you are trying to do, and any error messages you get. Also which Windows and Excel version you are using, and if 32 or 64 bit.

      Thanks

      Doug

      Like

    • dougaj4 says:

      The ALMatrixLib.dll file is now working on my new computer.

      I deleted the .tlb file and repeated the Regasm process, and the Alglib matrix functions are now working.

      Like

  5. Pingback: Installing C# dll files, reminder | Newton Excel Bach, not (just) an Excel Blog

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.