Author Topic: .NET to VB to VBA  (Read 2714 times)

0 Members and 1 Guest are viewing this topic.

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
.NET to VB to VBA
« on: August 24, 2009, 06:37:09 PM »
I'm getting tangled up in COM/.NET interop.
I'm updating some code for upgrade to 2010 so I'm running into compatability issues.
I've written a component in C#.NET that I use in VBA to allow dragging (jigging) of entities. So far, so good.
The component works fine when I use it from VBA.

Are you still reading? good.
Now I would like to use the same component from VB (a dll. referenced into VBA) and I'm running into problems.

When I try I get this error message:
Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException

Are you still reading? good.
So . . . I've got a VBA project (dvb) with a reference to a VB program (dll) that references a .NET component (dll).
Plus, the VBA project itself ALSO references the same .NET component.

Is this a recipe for disaster? Or should this work and I'm just missing something?
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: .NET to VB to VBA
« Reply #1 on: August 24, 2009, 06:52:54 PM »
you might try using [STAThread] in your managed code

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: .NET to VB to VBA
« Reply #2 on: August 24, 2009, 07:16:00 PM »
you might try using [STAThread] in your managed code
said the wise man.

That is exactly what it needed.
Thanks a million.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: .NET to VB to VBA
« Reply #3 on: August 24, 2009, 07:29:25 PM »
Glad it worked  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: .NET to VB to VBA
« Reply #4 on: August 24, 2009, 08:38:19 PM »

Well done.

I imagine a few people would like a cheat sheet for doing this ( in the near future).

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.