System.util.execute for excel macro

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.

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?

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?

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'])

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.

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.

2 Likes