Running Julia scripts from excel VBA

Hi

I am trying to run Julia scripts called from excel VBA under a Windows operating environment. I copied a program from the web, that supposedly works for Python scripts, and made the changes (see below). When I run the code from VBA, control passes to the command line and transfers to,
C:\Julia\julia-1.5.2\bin\julia.exe, stay there for a few seconds and then returns back to excel. Unfortunately the Julia script test.jl is not run. I suspect I am trying to do something impossible? Anyone got any ideas? Could be because the Julia file (test.jl) is not a *.exe file? If that is the case, is there anyway to make test.jl an exe file? Thanks again to those kind folks who might be able to help. Peter

Sub Run_Julia()

Dim objShell As Object
Dim Julia_Script, Julia_Exe As String

Set objShell = VBA.CreateObject("WScript.Shell")

Julia_Exe = """C:\Julia\julia-1.5.2\bin\julia.exe"""

Julia_Script = "C:\Users\peter\Documents\Julia_Code\Greenhouse_Model\Green-Lights-main\test.jl"

objShell.Run Julia_Exe & Julia_Script
 
Set objShell = Nothing

End Sub
2 Likes

I don’t have excel so I can’t try anything, but I’m curious why Juila_Exe is triple quoted but Julia_Script is only single quoted. I would probably try triple quoting Julia_Script (I’m guessing it’s done because of the back-slash). Or try single quoting both strings…

Thanks for response. The triple quotes were taken from the example for Python. I have tried double and single, but to no avail. I think my problem is that I need to make an a Julia “exe” type file. I am not sure that exists as yet. The quest goes on …I am sure there are many out in programming land that are looking for a GUI for julia? Excel was a reasonable choice for me.

The man page for Run in VB script is here:

https://ss64.com/vb/run.html

Looking at the examples toward the bottom there is:

objShell.Run ("%windir%\notepad.exe " & WScript.ScriptFullName)

Notice the space after notepad.exe. It looks like & just concatenates the strings together and attempts to execute the full string. At least that is my guess. :slight_smile:

Thanks. I am following up.

Just to let everyone know the following VBA code worked for runnining a julia script from excel (VBA)

Sub Run_Julia()

Dim objShell As Object
Dim Julia_Script, Julia_Exe As String

Set objShell = VBA.CreateObject("WScript.Shell")

Julia_Exe = """C:\Users\peter\AppData\Local\Programs\Julia 1.5.3\bin\julia.exe"""
Julia_Script = "C:\Users\peter\Documents\Julia_Code\Greenhouse_Model\Green-Lights-main\test.jl"
objShell.Run Julia_Exe & Julia_Script
 
Set objShell = Nothing

End Sub

Case closed!