I wrote a C# .dll in Visual Studio which I want to call from excel VBA. (I used this tutorial)
On my Development PC where I set the settings in the Project properties for "Make COM-Visible", "Register for COM interop" and "sign the assembly" it all works fine. The dll is getting registered automatically by Visual Studio and I can select and set it in Excel in VBA Window > Tools > References
The use case now is that I can use that dll file on another PC which does not have Visual Studio installed.
As told in the tutorial and all around the internet the way to go is by using the command line tool RegAsm.exe, what I did (if its useful: I used the one in the following folder: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe)
The command to register the dll is:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe D:\Debug\DotNetLibrary.dll /tlb /codebase.
This runs without an error and the command line tells me that the types have been registered correctly and the tlb has been exported and registered.
It seems like everything worked well and there is also an entry in the registry (Computer\HKEY_CLASSES_ROOT\TypeLib) which references my dll but the library doesn't show up in the Reference window in VBA like it did on the other PC.
If I select the tlb, which has been generated by the RegAsm manually, by clicking browse in the Reference Window, it gets added to the list. But if I then start the code I get the Error that the ActiveX component can't create an object.
I'm inspecting this issue since several days now, so it would be very nice if some one could assist me with it.
As #HansPassant mentioned in an comment under my question the simple solution was to use the 32-bit version of regasm (located in C:\Windows\Microsoft.NET\Framework\v4.0.30319)
This needs to be done because Microsoft Office products are still 32-bit.
Related
I created a software program ages ago, and have just opened up the project and when I try to compile, it throws up two errors in reference to VBIDE:
Warning 2 Cannot find wrapper assembly for type library "VBIDE". Verify that (1) the COM component is registered correctly and (2) your target platform is the same as the bitness of the COM component. For example, if the COM component is 32-bit, your target platform must not be 64-bit. SonicPhoto
...and:
Warning 3 The referenced component 'VBIDE' could not be found.
The thing is - I don't ever remember adding this reference as my project is a sound orientated program and VBIDE is "Microsoft Visual Basic for Applications Extensibility 5.3" which has nothing to do with C#, let alone my program. If I remove the reference, the solution compiles and seems to run perfectly. I presume I am completely safe to remove it if it runs?
Perhaps I added this reference by mistake? Just to also say, I have older archived of my software, and the reference is there too, and none of the those compile either, when I know for a fact that at least one of the older copies of my software would have compiled. I also have a copy on another computer, and the reference is there too, but the reference isn't broken, so the project compiles and runs.
On Solution Explorer,
Click Show all Files,
Click References,
Select VBIDE,
RightClick it and Remove it.
As WelcomeOverflow suggested this solved it for me:
Microsoft Visual Basic for Applications -> Menu -> Extras -> Links
-> [x] Microsoft Visual Basic for Applications Extensibility 5.3
I know this is necroing a post but I had the same issue and solved it.
I have visual studio code I am trying to compile/build from source and did not have this VBIDE reference. I also needed RSlinx installed for an OPCautomation reference (its an industrial driver program for Rockwell automation) and Microsoft office since the program is creating an excel file.
Any who, long story short after I installed office 365 visual studio suddenly had the Vbide reference which it could not locate before. Deleting the Vbide reference also allowed it to compile so I would back up the program and try that first.
Cheers
Ran into the same problem.
Installed Office 2007 and the problem was fixed
I created a COM class library using my VS2013. I went into the library properties and Compile -> Register for COM interop is checked. I then built the library and see the .tlb file that it generated. At this point I am wondering if there is anything additional that I have to do with the library properties.
I then used RegAsm sample.dll tbl:/sample.tbl
Would the next step be to simply reference the tbl from my VB6 app? I keep getting an error when trying to use the CreateObject function: 429 ActiveX Component can't create object
If my COM library is created properly with GUIDS/Settings based on tutorials and I registered it with RegAsm is there anything that I could be missing?
I had the same problems registering a COM-Interop-DLL. I finally used the InstallShield limited edition setup project to get it running. It's free and replaces the old MS setup project. You need to register to download the software and get a licence.
In the tab Application Files add the needed files. In the properties of the files / tab COM & .NET Settings set the check box COM Interop (this is what I'done) and then create the output.
This is what worked for me.
Christian
I have a DLL that I want to use in C# projects as well as Excel VBA. I used regasm.exe to register the DLL and create a TLB . I was now able to reference it in VBA. My problem is, that I would need to my C# apps still can't find the DLL. I would have to add either a copy of the DLL or a .config - file in the folder of each C# app for them to work. I can see the reference in Visual Studio under COM, but get an error when trying to use that reference (something Active-X related, I can look it up if it's important).
So I tried using gacutil.exe (unregistered first with regasm.exe) and registered my DLL in GAC. Now I don't need the copy or .config, my C# apps work again. Excel VBA still needs the registration with regasm.exe though, I can't add a refrence after only using gacutil.exe.
Here my question: How do you register a DLL when you want to use it for C# apps AND Excel VBA? Is it possible to use both regasm and gacutil without having any problems?
After running regasm you can then use gacutil /i to install the assembly into the GAC. Once this is done, add a reference to the assembly to your .NET project using the Browse tab. Once the reference is added, locate the reference in the project and view the properties for that reference. Change "Copy Local" to "False".
At run time your .NET project will look for the assembly locally and, when it cannot find it, will then check the GAC. Assuming you've run the gacutil command it will then locate it there.
A somewhat different approach is to incorporate your C# library in an Excel-DNA .xll add-in. This allows you to make the library available to VBA in Excel without registration or requiring admin rights, and the same add-in can include worksheet UDF functions, ribbon customization etc..
A detailed write-up of exposing C# libraries to Excel VBA via Excel-DNA by Mikael Katajamäki can be found here:
http://mikejuniperhill.blogspot.com/2014/03/interfacing-c-and-vba-with-exceldna-no.html and
http://mikejuniperhill.blogspot.com/2014/03/interfacing-c-and-vba-with-exceldna_16.html.
I am attempting to distribute a .NET Wizard form for Visual Studio, using a non-msi installer. For the sake of simplicity, let's focus on Visual Studio 2008.
So, as part of the post-build process of the assembly, I call:
regasm /regfile C:\path\to\my\assembly.dll
Then, pack the generated regfile and use regedit to merge this with the end users registry. I see that the assembly name and CLSID are generated properly and placed into HKEY_CLASSES_ROOT and HKEY_CLASSES_ROOT\CLSID, respectively.
However, on the Visual Studio side of things, after the installation is complete, I get an error. To elaborate, the Wizard is seen in the "Add New Items", via the vsdir file. This points to the vsz file, where Visual Studio sees the appropriate COM class. I can tell that it sees this class in HKEY_CLASSES_ROOT because the error message actually displays the correct CLSID:
Class not registered.
Looking for object with CLSID: {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
I am not entirely sure what the problem is. I know that the old InstallShield project had a simple check box for installing assemblies as COM interop. Unfortunately, this is not available to me. Perhaps that isn't really the problem and I am missing something from the Visual Studio 2008 installation side of things.
Any ideas or debugging help would be greatly appreciated. First and foremost, I want to verify that the assembly is correctly installed for COM interop. I have never used COM before, so it is all greek to me. :)
Edit: I should mention that this same assembly was build and distributed just fine with an "old" InstallShield project. Therefore, I know the problem lies within my own understanding/implementation of adding a .NET COM Wizard to the Visual Studio Add Items dialog.
Does your class (or assembly) have the Com visible attribute set to true?
My project has many COM dependecies.
as you know , in order to use COM dlls you must register them using REGSVR32.
this creates alot of mess when immigrating to other computer/ installation.
currently got them all in a dependecy folder. and got a batch file that runs pre build and registers all of the dlls.
how do you manage your com dlls?
what is the easiest way to find out if your com dll registered, and if not to register it?
how to make sure that if I get lastest version of the project to a computer that never used it before.
(only got visual studio) I can just do rebuild all and all will compile and work. and as cleanly and as simple as possible.
do you put all your resources as part of the soultion? I mean project documents mail conversation and etc? looks like visual studio can manage all those easily but is this a known practice?
i am using studio 2010