0
votes

I have a code that opens an external programme's application window as a VBA object. The code opens a GUI in that external programme that the user then interacts with. I currently have an issue where the code runs through to the end of the sub routine and subsequently closes the object I have created. As an interim measure, I have added a 'Stop' command but this is untidy allowing users to edit the code.

Anyone have any ideas that would allow me to run the code in the background but keep the object open indefinitely?

Sub Exit_Click()

Dim MatLab As Object
Dim Result As String

Set MatLab = CreateObject("Matlab.Application")

'Calling MATLAB function from VB

Result = MatLab.Execute("cd \\ariaimg\va_data$\RPM_Database\RPM_database\RPM_Evaluation")
Result = MatLab.Execute("RPM_GUI")

Stop

End Sub
1

1 Answers

2
votes

Declare the Matlab Object outside the sub procedure, at the top in the declarations part of your module. So "Dim MatLab As Object" should be outside the Exit_Click sub procedure. This will set module level scope to the Matlab Object instead of private scope as you have declared now.