Maury Markowitz
Maury Markowitz

Reputation: 9273

.net objects for 32 or 64 bit Excel?

I have a VB.net project that builds and registers a COM library that I can open and use in Excel on my development machine. That machine happens to have 32-bit Excel. On my other machine Excel installed in 64-bit and will not open the library, 429.

Other threads have suggested that the code itself is likely fine, as long as I compile under "Any".

Is that correct? Is code compiled for "any" generally able to run on 32 and 64-bit?

The same threads suggest that the only real problem is the tlb/registration, and point to articles that suggest manually calling regasm to avoid this.

Is this correct?

If so, am I supposed to have two tlb files? Or two COM libs? Or just one?

Upvotes: 0

Views: 1960

Answers (1)

Maury Markowitz
Maury Markowitz

Reputation: 9273

Ok, it's working. I still don't understand why this solution works, but here it is:

  1. compile the DLL using the "Any CPU" setting
  2. turn OFF COM registration, it doesn't hurt but it will just confuse things later
  3. add two lines to your VS project's post-build:

    "%Windir%\Microsoft.NET\Framework\v4.0.30319\regasm" "$(TargetPath)" /tlb:DCFPropery32.tlb

    "%Windir%\Microsoft.NET\Framework64\v4.0.30319\regasm" "$(TargetPath)" /tlb:DCFPropery64.tlb

  4. copy the DLL and TLB's to the target machine

  5. determine the bit-ed-ness of the target machine's office:

    http://www.howtogeek.com/howto/24259/

  6. run the correct version (32 or 64) of regasm on that machine with the following switch:

    FOR 32-BIT OFFICE c:\windows\microsoft.net\frameworks[version number]\regasm [path to dll] /codebase

    FOR 64-BIT OFFICE c:\windows\microsoft.net\frameworks64[version number]\regasm [path to dll] /codebase

  7. open Excel on the target platform and navigate to the VBA editor's References dialog. Browse… to the location of the files, and select the correct bit-edness version of the TLB for your platform.

And hopefully that works for all of you too!

This solution is far from ideal. For one, Microsoft keeps moving the location of regasm, so there's no simple way to script this. For another, I have no idea idea why I need to call /codebase, but it appears to have something to do with the naming of the files. Finally, this means that all such work will require at least a little manual work on each and every machine you want to run it on, or you'll need to go through the trouble of making an installer!

Upvotes: 1

Related Questions