# Running Julia scripts from excel VBA

**URL:** https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022
**Category:** General Usage
**Created:** [January 27, 2021, 12:57am UTC](https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022 "2021-01-27T00:57:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Peter-Jolly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter-jolly/32/19371_2.png) [@Peter-Jolly](https://discourse.julialang.org/u/Peter-Jolly)
#### Post date: [January 27, 2021, 12:57am UTC](https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022/1 "2021-01-27T00:57:02Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [January 27, 2021, 8:06pm UTC](https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022/2 "2021-01-27T20:06:16Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![Peter-Jolly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter-jolly/32/19371_2.png) [@Peter-Jolly](https://discourse.julialang.org/u/Peter-Jolly)
#### Post date: [January 27, 2021, 11:40pm UTC](https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022/3 "2021-01-27T23:40:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)
#### Post date: [January 28, 2021, 12:23am UTC](https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022/4 "2021-01-28T00:23:15Z")

</div>

The man page for Run in VB script is here:

[https://ss64.com/vb/run.html](https://ss64.com/vb/run.html)

Looking at the examples toward the bottom there is:

```julia
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. 🙂

---

<div class="post-metadata">

### Author: ![Peter-Jolly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter-jolly/32/19371_2.png) [@Peter-Jolly](https://discourse.julialang.org/u/Peter-Jolly)
#### Post date: [January 28, 2021, 9:44pm UTC](https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022/5 "2021-01-28T21:44:52Z")

</div>

Thanks. I am following up.

---

<div class="post-metadata">

### Author: ![Peter-Jolly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter-jolly/32/19371_2.png) [@Peter-Jolly](https://discourse.julialang.org/u/Peter-Jolly)
#### Post date: [February 9, 2021, 10:24pm UTC](https://discourse.julialang.org/t/running-julia-scripts-from-excel-vba/54022/6 "2021-02-09T22:24:59Z")

</div>

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

```julia
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!
