# System.util.execute for excel macro

**URL:** <https://forum.inductiveautomation.com/t/system-util-execute-for-excel-macro/36864>\
**Category:** Ignition\
**Created:** [July 20, 2020, 1:12pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-for-excel-macro/36864 "2020-07-20T13:12:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve.richardson](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@steve.richardson](https://forum.inductiveautomation.com/u/steve.richardson)\
**Post date:** [July 20, 2020, 1:12pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-for-excel-macro/36864/1 "2020-07-20T13:12:24Z")

</div>

I’ve been trying to get an excel macro to run from a Gateway event script, but can only get it to work from the script console.  
This is the part I’m testing:  
from time import localtime, strftime  
execTime = strftime("%H:%M", localtime())  
if execTime == “10:25”:  
system.util.execute([‘C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE’, ‘C:\data\some\_macro.xlsm’])

I’ve read about the System service account not having rights to run windows applications, and I’ve tried allowing that account to interact with desktop. Also tried setting the service logon to use an Administrator account instead. Those don’t seem to work, and I didn’t see a solution to anyone’s problems.  
How do you get a Gateway script to run and Excel macro?

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 20, 2020, 1:19pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-for-excel-macro/36864/2 "2020-07-20T13:19:59Z")

</div>

If it’s working from the Script Console and not your gateway event script then you could be running into a scope issue (client vs gateway).

Is the gateway service running on your localhost or remote server?

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [July 20, 2020, 1:33pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-for-excel-macro/36864/3 "2020-07-20T13:33:40Z")

</div>

When I copied what you had on here, it did something with the quotes around the time in your if statement and in your execute statement. I'm assuming something changed when you copied it over though. I'm not sure why it would run from your script console though. Backlashes are considered escapes in python. Have you tried doubling them up and seeing if you get a different result?

> [@System.util.execute() to pass parameters into excel file](http://forum.inductiveautomation.com/t/system-util-execute-to-pass-parameters-into-excel-file/34938/2):
>
> Backslashes are escapes in python quoted strings. Try doubling them up. Or just switch them to forward slashes.

```auto
from time import localtime, strftime
execTime = strftime("%H:%M", localtime())
if execTime == "10:25":
	system.util.execute(['C:\\Program Files\\Microsoft Office\\root\\Office16\\EXCEL.EXE', 'C:\\data\\some_macro.xlsm'])

```

---

<div class="post-metadata">

**Author:** ![steve.richardson](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@steve.richardson](https://forum.inductiveautomation.com/u/steve.richardson)\
**Post date:** [July 20, 2020, 1:45pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-for-excel-macro/36864/4 "2020-07-20T13:45:16Z")

</div>

In this case, the gateway is the client - running on the same computer. But your comment gave me an idea. I moved the script from Gateway to Client events, and Excel opened.  
So what’s the difference between the two environments? I have a csv creation script that runs fine under the Gateway scope.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 20, 2020, 3:38pm UTC](https://forum.inductiveautomation.com/t/system-util-execute-for-excel-macro/36864/5 "2020-07-20T15:38:30Z")

</div>

> [@steve.richardson](#):
>
> system.util.execute([‘C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE’, ‘C:\data\some\_macro.xlsm’])

`excel.exe` is a graphical program - Windows won't allow background services (IE, the Ignition gateway) to run programs that require a GUI. Open it from the client scope is the correct thing to do - even if you could open it from the gateway, it wouldn't actually display in any user sessions.
