none
Self registering VBA via deployment of .NET RRS feed

  • Question

  • Hi

    I am looking to do a self registering of a .NET com dll in VBA using Regasm -- I would like to get code to check the version of .NET on the machine then registering the DLL depending on the version on the machine. The dll is registered with Visual Basic 2005 .NEt v2.0.50727. I dont want to run into incompatibilities with wrong version of .NET - How can I accomplish it . My application is an Exe that call  excel

    The code i have below will check the version of Excel and add the references....I would like to to register the dll with the same procedure with regasm.

    Sub Ref()
         
            On Error GoTo MyError
         
            Dim oApp As Object
            Dim sVersion As String
            Set oApp = GetObject(, "Excel.Application")
            If TypeName(oApp) = "Nothing" Then
                Set oApp = CreateObject("Excel.Application")
            End If
            Select Case Left$(oApp.Version, InStr(1, oApp.Version, ".") + 1)
                Case "8.0"
                    sVersion = "97"
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                    On Error Resume Next  'Ignore Error If Reference Already Established
                Case "9.0"
                    sVersion = "2000"
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                    On Error Resume Next  'Ignore Error If Reference Already Established
                 Case "10.0"
                    sVersion = "2002"
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                    On Error Resume Next  'Ignore Error If Reference Already Established
                Case "11.0"
                    sVersion = "2003"
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                On Error Resume Next  'Ignore Error If Reference Already Established
                Case "12.0"
                    sVersion = "2007"
                    
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                    On Error Resume Next  'Ignore Error If Reference Already Established
                Case "14.0"
                    sVersion = "2010"
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                    On Error Resume Next  'Ignore Error If Reference Already Established
                Case "15.0"
                    sVersion = "2013"
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                    On Error Resume Next  'Ignore Error If Reference Already Established
                Case "16.0"
                    sVersion = "2016"
                    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Appname\MainLibrary.tlb"
                    On Error Resume Next  'Ignore Error If Reference Already Established
                Case Else
                    sVersion = "Undetermined!"
                    ThisWorkbook.Close
                    
            End Select
            'MsgBox "Excel version: " & sVersion
            Exit Sub
    MyError:
            If Err.Number = 429 Then
                Resume Next
            Else
               ' MsgBox Err.Number & " - " & Err.Description
            End If
        End Sub


    • Edited by JohnGreen09 Monday, October 23, 2017 3:00 PM
    Monday, October 23, 2017 2:59 PM

All replies

  • It is unclear to me what you are asking. You say "do a self registering" then you say "get code to check the version of .NET then registering the DLL". I don't understand how the .Net version is relevant to the use of regasm and I am not sure how much of all that that you are asking how to do.

    Note the source code for regasm is available; I don't know where but it could be found if necessary. Usually the only thing it does is to call DllRegisterServer in the relevant DLL and the DLL does whatever needs to be done.



    Sam Hobbs
    SimpleSamples.Info


    Monday, October 23, 2017 5:21 PM
  • It is unclear to me what you are asking. You say "do a self registering" then you say "get code to check the version of .NET then registering the DLL". I don't understand how the .Net version is relevant to the use of regasm and I am not sure how much of all that that you are asking how to do.

    Note the source code for regasm is available; I don't know where but it could be found if necessary. Usually the only thing it does is to call DllRegisterServer in the relevant DLL and the DLL does whatever needs to be done.



    Sam Hobbs
    SimpleSamples.Info


    Sam ok let me explain

    I have an excel application. I have written the macro to VB to a dll to protect it.I want to run my excel application calling the dll. I want to rollout the software to different machines with different versions of .NET. My dll I need to register on all the workstations so that they can run the application. I dont want to run into problems with different incompatibilities on different Microsoft. Net versions and frameworks.....thats why I am looking for a solution to check the machine what version of .Net its running then change to the right . Net directory to run the regasm to register the dll. Hope this make sense to you now

    Thanks for any help





    • Edited by JohnGreen09 Monday, October 23, 2017 5:43 PM
    Monday, October 23, 2017 5:38 PM
  • What part of that are you asking for help with?


    Sam Hobbs
    SimpleSamples.Info

    Monday, October 23, 2017 9:20 PM
  • I use Inno Setup to install my apps.  Here is a link on how to check the .Net version.

    When possible I use .Net Core 2.0 for all my C# apps.  You can check the version by:

    C:\Program Files\dotnet>dotnet --version
    2.0.2

    • Edited by mogulman52 Tuesday, October 24, 2017 1:41 PM
    Tuesday, October 24, 2017 12:24 PM
  • I think you're going to find self-registering a .NET component with a COM interface from VBA to be problematic, since you will want to use the Regasm codebase option if you are not installing in the GAC. I would recommend using an installer, as suggested by mogulman52, because this operation will also require elevated (administrator) privileges.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, October 24, 2017 10:37 PM