Home > OS >  Working with Excel 4.0 for work, trying to use a button to launch a python script
Working with Excel 4.0 for work, trying to use a button to launch a python script

Time:04-19

So, the shop where I work use Excel 4.0 for all its inventory management and orders. Since the guy before me left without explaining anything, I inherited an old system that works, but is... eh. The bosses don't want to change to a new Excel nor another program, so I must do what I can with what I have.

Now, I've made a script in python 2.5.4 (this version is needed because the newer versions won't work on the Windows 98 computer they use...) to automate some processes that would be impossible with Excel 4.0 macros, and the script works perfectly for what I need. But since the bosses want to "only work with Excel", and won't want to go outside of Excel and click the script icon to start it (or, heaven forbid, open cmd and start it manually), I would need to put a button in Excel to start the script. I've tried to sift through the macros available, but except perhaps "Initiate" (which I don't wholly understand as of now), I can't think of a macro to interact with the script, and haven't found much help with what's available online...

SO, could anyone please help me in making the macro for the button? The only thing the button would need to do is to start the python script, there's no other interactions needed, the rest is done by the script.

Like, the script "foo.py" is in the same folder as "bar.xls", and I only need a button in "bar.xls" to launch "foo.py". Thanks.

CodePudding user response:

Okay, I found a roundabout way, so I'm gonna share it with y'all.

MacroName
=LAUNCH("cmd",1)
=SEND.KEYS("foo.py~";TRUE)
=SEND.KEYS("exit~")
=RETURN()

It opens a cmd instance, show it for a split second (can't use SEND.KEYS without it being the active app), writes the name of the python script and presses enter, before quitting.

I would like if it didn't need to show the cmd window, but it works for now. Perhaps there'll be another way, but if anyone else wanna do what I did, it does work.

CodePudding user response:

You probably need to get the book out - Excel 4 came with one book called the Function Reference which listed all the commands available.

Commands that we used back in the day were:

EXEC: starts another program

EXECUTE: runs commands in another program called by Initiate

INITIATE: sets a channel to a program

SEND.KEYS: sends keystrokes to a program (we used to send data to a slow server this way...)

Not sure what will be on the web for Excel macro 4, it was retired as vba came out and Excel moved over...

I still use my copy of the book, but it would be worth finding, although the help should list the commands as well. I just used the book as I had macros running...

  • Related