currently I am using Arena Simulation for an acadamic project. I want to start the a model of the acadamic Arena version via VBA, run the model and close it automatically.
Until now the Arena model opens but is not running. The click on the run button (to start the model simulation) in Arena is missing. How can I "click" the run button in VBA?
My current code section:
Private Function ExecuteArena(ByVal arenaFile As String, ByVal arenaPath As String)
On Error GoTo ErrorHandler
''' Clear the error mesaage variable.
gszErrMsg = vbNullString
''' Shell out
If Not bShellAndWait(arenaPath & " " & arenaFile & " ", 6) Then Err.Raise 9999
Exit Function
ErrorHandler:
''' If we ran into any errors this will explain what they are.
MsgBox gszErrMsg, vbCritical, "Shell and Wait Error"
End Function
Private Function bShellAndWait(ByVal szCommandLine As String, Optional ByVal iWindowState As Integer = vbHide) As Boolean
Dim lTaskID As Long
Dim lProcess As Long
Dim lExitCode As Long
Dim lResult As Long
On Error GoTo ErrorHandler
''' Run the Shell function.
lTaskID = Shell(szCommandLine, iWindowState)
''' Check for errors.
If lTaskID = 0 Then Err.Raise 9999, , "Shell function error."
''' Get the process handle from the task ID returned by Shell.
lProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, lTaskID)
''' Check for errors.
If lProcess = 0 Then Err.Raise 9999, , "Unable to open Shell process handle."
''' Loop while the shelled process is still running.
Do
''' lExitCode will be set to STILL_ACTIVE as long as the shelled process is running.
lResult = GetExitCodeProcess(lProcess, lExitCode)
DoEvents
Loop While lExitCode = STILL_ACTIVE
bShellAndWait = True
Exit Function
ErrorHandler:
gszErrMsg = Err.Description
bShellAndWait = False
End Function