How to register your tlb file for VBA use on a destination machine AND have VSTO running. SUCCESS.

It took HOURs to figure all this out and the answer!? (see older post) The issue that we are having is that  the VSTO would work initated from the ribbon, but the VBA when you added a “reference” to the .tlb file would tell you that it could not create an ActiveX object or other message saying “what!?”. Solution:  to run from the command line:  

regasm /codebase <pathToMyDll> /tlb:<pathToMyTlb>

But that command too could not “just run”. Here is a guy doing the exact same thing as me, except I found this article last – or at least I stopped looking. It is the key. Making VSTO things and wanting to use them in the “old world” and the new. This confirms all I have learned. Lots of links at the bottom about CLSID’s, regasm etc. COM====ActiveX in case you run into ActiveX – it is 100% the same. I used RegShot to see the registry items to learn what to google next

Microsoft has set up MASSIVE hoops to jump through yet again. You have to sign your project with a strong name and to learn how to do that … follow the links under the section How to Make a Strong Name … or cheat like I did.

  • go to your project’s Properties and click on Signing.
  • On the bottom section: check “Sign the Assembly”
    • in the pulldown – choose <new>
    • Make a good file name and end it with “0”
      • and assign a password
    • Make ANOTHER one and give it the same file name and end it with “1” (same password is handy)
  • In the top section – click “Select from file” and choose the name ending with the 0 after entering the password
  • Make sure your version control software (I am using git) allows the .pfx files to be stored. This whole excercise is to get a unique ID – not for security so the password I chose was super simple
  • Settle down the random GUID generation for your COM Class and Interface (do this to reduce mayhem)

Then, to make the regasm command above easy I added it as a step in the InstallShield wizard – but to do that … it has to be a cscript or wscript file. I made a .vbs script file and ironically had to run it with cscript as I used a library that only cscript would use. Here is the code. Making an exe might have been easier.

' bind a variabe to WScript.Shell
Set WshShell = CreateObject("WScript.Shell")

' define the path to the regasm.exe file
RegAsmPath = "c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe"
ProgramDir = "elbsolutions\xladdinTest1"
DllFile = "HplAddinAGSL.dll"
TlbFile = "HplAddinAGSL.tlb"

' register the dll
TotalCommand = "cmd /c " &amp;amp;amp;amp; RegAsmPath &amp;amp;amp;amp; " ""%ProgramFiles%\" &amp;amp;amp;amp; ProgramDir&amp;amp;amp;nbsp; &amp;amp;amp;amp; "\"&amp;amp;amp;nbsp; &amp;amp;amp;amp; DllFile &amp;amp;amp;amp;&amp;amp;amp;nbsp;&amp;amp;amp;nbsp; """ /codebase /tlb:""%ProgramFiles%\" &amp;amp;amp;amp; ProgramDir&amp;amp;amp;nbsp; &amp;amp;amp;amp; "\"&amp;amp;amp;nbsp; &amp;amp;amp;amp; TlbFile &amp;amp;amp;amp;&amp;amp;amp;nbsp; """ 1&amp;amp;amp;gt;&amp;amp;amp;amp;2&amp;amp;amp;gt;""%ProgramFiles%\" &amp;amp;amp;amp; ProgramDir&amp;amp;amp;nbsp; &amp;amp;amp;amp; "\registerResults.txt""" TotalCommand, 0, True
Set objStdOut = WScript.StdOut
Wscript.StdOut.WriteLine TotalCommand

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "%ProgramFiles%\" &amp;amp;amp;amp; ProgramDir&amp;amp;amp;nbsp; &amp;amp;amp;amp; "\registerResults.txt"
strFile = WshShell.ExpandEnvironmentStrings(strFile )
Wscript.StdOut.WriteLine strFile
Set objFile = objFS.GetFile(strFile)

Set ts = objFile.OpenAsTextStream(1,-2)

Do Until ts.AtEndOfStream
strLine = ts.ReadLine
' do something with strLine
Wscript.StdOut.WriteLine strLine


How to Make a Strong Name – the list of hoops

Regasm.exe (Assembly Registration Tool)

Other Links for learning about Registry Keys and COM (or ActiveX)


Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *

Please answer the question so the system knows your a human and not a web-bot * Time limit is exhausted. Please reload CAPTCHA.