views:

31

answers:

2

Hi, I'm developing a VB6 standalone application that I'd like to be able to call from VBA modules running in Excel, Outlook, etc. Ideally, I'd like the VBA module to check whether the VB6 application is already running, if not, open it, then populate certain controls (textbox, listbox, etc) in the VB6 application with information from the VBA module. Is this even possible? Can I just create a reference somehow to the VB6 application, then treat it like any other object? Thanks for your help!

+2  A: 

Make the Vb6 app into an ActiveX Exe project. Here's the VB6 manual tutorial on creating an ActiveX exe. Add a reference to the vb6 from the VBA code. You will be able to call into objects in the Vb6 from your VBA.

Use GetObject to instantiate a Vb6 object from the VBA. That will connect to any existing instance of the vb6 app, or start a new instance if necessary.

MarkJ
Thanks for the great VB6 tutorial - I learned a lot from that. I can now call and interact with the classes in the VB project, but I haven't figured out how to interact with the controls (textboxes, listboxes, etc). Any suggestions?
@user425751 Create methods in the public objects that interact with the controls on your behalf. You can't manipulate the controls directly from outside the exe, but you can call methods that do it for you.
MarkJ
A: 

You cannot do as you describe and treat the VB6 app like and object but you could do it in the following way:

  1. Use the FindWindow API call to determine if the VB6 application is running
  2. Use the Shell command to start it
  3. Use AppActivate to make VB6 window active and SendKeys to send the data to it

That would be the simplest "out of the box" solution. However, this will be quite brittle. For example, if you removed controls from the VB6 form or changed the tab order of the controls, your app will malfunction!

Another option is DDE but I think the DDE link is intended to go from the VB6 app to Word or Excel, not the other way around.

Ken Keenan