开发者

Passing an object from VBA to VB

开发者 https://www.devze.com 2023-03-28 07:15 出处:网络
I work with an accounting package that supports VBA.When the accounting system runs a VBA macro it passes a \'Session\' object that includes signon information that can be used to access other parts o

I work with an accounting package that supports VBA. When the accounting system runs a VBA macro it passes a 'Session' object that includes signon information that can be used to access other parts of the accounting package. I can create a VB6 application开发者_运维百科 and reference a the COM library where this Session type is defined. When I run the VB6 application I have to initialize the Session variable which involves signing on to the accounting system and I end up using another concurrent license. If I stick with VBA I don't have this limitation but then I'm stuck with VBA.

What I'm trying to figure out is if there is a way to have a VBA macro that has this Session object already initialized send this Session object to a VB program. I'm thinking that I can create a DLL that the VBA macro calls and passes the Session object to. Then the DLL can execute a VB program, itself. That VB program (I hope) can make a call back to the DLL to get access to the Session variable. I'm thinking that if the VB program was invoked by the DLL that the VB program should have access to the shared memory.

So the question is: Can I have a VBA program invoke a DLL, pass a COM object to that DLL, have that DLL invoke a VB program and have that COM object available to the invoked VB program?


I'm gonna say no. You should be able to create a VB6 (or even .NET) dll that can access a passed in Session object, but you cannot then pass that object out of process from the accounting package (which created and initialized the Session object for you) to circumvent the licensing. But you can just put the logic you need inside the DLL.


Let me take a stab at this one. My preferred method is just to do everything in .NET using XL-DNA or some other like program (I just stick with XL DNA since it's free and works great). There are paid programs that make the work even easier.

For an approach that you are talking about here's a couple of references that might help, I've never worked with them so good luck!

http://support.microsoft.com/kb/317535

http://www.xtremevbtalk.com/showthread.php?t=303014

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号