beachbum714
asked on
How to call a public property in a VBA project at runtime from a VB app
I have a public property in a VBA project of a non-office product that I want to "fill" from a VB app. I can't find any definitive documentation on this subject. How do I pass data directly to an object in the VBA Project?
I think with Automation but without more data i can't help.
ASKER
I have a class in a VBA project of an Arena 6.0 simulation model. It contains a publicnotcreateable class clsVBData, whicn in turn contains a public property SimulationID. I need to pass a long value to it from a VB 6.0 application. As the model/project is not compiled into an executable and registered, it can not be referenced. In otherwords, its not an ActiveX control or the like. The VBAproject portion of the model's doe file doesn't have a public interface. I have temporarily solved it by putting the value to pass into a table in an mdb file and pull it in from the VBA project.
The VBA class is not public, but the projecjt should be. I tried every which way I can with automation with no luck nor any solid documentation except that even Microsoft says it can be done by creating an instance (only one) within the VBA project. That still leaves me with no way to pass in a value to the VBA project.
The VBA class is not public, but the projecjt should be. I tried every which way I can with automation with no luck nor any solid documentation except that even Microsoft says it can be done by creating an instance (only one) within the VBA project. That still leaves me with no way to pass in a value to the VBA project.
this is a guess and a hack:
Create a property for the main document of your program that maps to class property.
I think it could be read by automation.
Create a property for the main document of your program that maps to class property.
I think it could be read by automation.
ASKER
Yeah, I've tried that. It didn't work. That was the first thing I thought of. The VBA Project/Model document is not ActiveX so direct automation didn't apply. I have the software mfg company looking into it and begging them to open up the the interface to the project. There were other automation issues I have with them. Its just that the VBAProject should have automation and I can't find a way to access it.
You cannot directly access a VBA project's class module's properties and procedures. But you may be able to access it indirectly.
I don't know about Arena 6.0 so I'll show how to do it in Access.
Let's say there is an Access database with a standard module, Module1, and a class module, Class1.
Class1 contains the following code.
Public stMsg As String
Public Sub Msg()
MsgBox stMsg
End Sub
Module1 contains the following code.
Public Sub RunClass1Msg(stMsg As String)
Dim cls1 As Class1
Set cls1 = New Class1
cls1.stMsg = stMsg
cls1.Msg
Set cls1 = Nothing
End Sub
In VB6 there is a form with a command button. Set a reference to the Access object model.
The form contains the following code.
Private accObj As Access.Application
Private Sub Command1_Click()
If accObj Is Nothing Then
'Open the database if it's not open
Set accObj = Access.Application
accObj.OpenCurrentDatabase "D:\My Documents\Access\ButtonTes t.mdb"
End If
'Use Access Run method to indirectly create an instance of Class1,
'set it's stMsg property and run it's Msg sub
accObj.Run "RunClass1Msg", "Here."
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set accObj = Nothing
End Sub
When command1 is clicked a message box will open displaying "Here."
Hope this helps.
gaw
I don't know about Arena 6.0 so I'll show how to do it in Access.
Let's say there is an Access database with a standard module, Module1, and a class module, Class1.
Class1 contains the following code.
Public stMsg As String
Public Sub Msg()
MsgBox stMsg
End Sub
Module1 contains the following code.
Public Sub RunClass1Msg(stMsg As String)
Dim cls1 As Class1
Set cls1 = New Class1
cls1.stMsg = stMsg
cls1.Msg
Set cls1 = Nothing
End Sub
In VB6 there is a form with a command button. Set a reference to the Access object model.
The form contains the following code.
Private accObj As Access.Application
Private Sub Command1_Click()
If accObj Is Nothing Then
'Open the database if it's not open
Set accObj = Access.Application
accObj.OpenCurrentDatabase
End If
'Use Access Run method to indirectly create an instance of Class1,
'set it's stMsg property and run it's Msg sub
accObj.Run "RunClass1Msg", "Here."
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set accObj = Nothing
End Sub
When command1 is clicked a message box will open displaying "Here."
Hope this helps.
gaw
Is Run command usefull with properties?
No. The Run method can only run a user-defined function or sub procedure in a standard module. However, the function or sub called can set properties and instantiate objects in the application.
gaw
gaw
ASKER
Arena doesn't have a Run method t hat I know of. I passed it along to Rockwell Software Tech Support and have heard nothing back. They've never had the kinds of requests or questions I've given them. I guess I am keeping them busy. I will let you know if they have something similar. So far your solution isn't feasible do to their closed version of VBA.
Hi beachbum714,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Refund points and save as a 0-pt PAQ.
beachbum714, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit. Explain why.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Refund points and save as a 0-pt PAQ.
beachbum714, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit. Explain why.
==========
DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.