Page 1 of 1

BATCH interactions with opened .exe

Posted: 16 Mar 2019 08:15
by Mado91
Hi everyone,
I'm a self-taught (nice way to mean "noob") programmer and that's my first approach to DOS comands and .bat files. I've already written a couple of .bat that can do basic things with inputs, so now I wonder: is it possible to make a .bat program opens an .exe and interact with it? For example, can I write a .bat that can open a .xlsm file and make it execute a macro written in VBA?
Thanks

Re: BATCH interactions with opened .exe

Posted: 16 Mar 2019 13:03
by aGerman
Short answer: No.

Long answer:
Batch cannot interact with graphical user interfaces.
For your example that means you can open an .xlsm file but you can't make it execute a certain macro. That's the responsibility of Excel. You can write a macro that gets automatically executed if the file was opened. But again, you have to specify that in the .xlsm file itself.

Steffen

Re: BATCH interactions with opened .exe

Posted: 17 Mar 2019 04:09
by Mado91
Hi, thanks for the answer. So now I wonder... what level of "freedom" can I have to interact with non-bat files? For example, I know that DOS can create and edit txt files, or even edit a previously existing file. I made experiments using the following code:

Code: Select all

set /P input=
echo %input% >> output.txt
or even

Code: Select all

set /P input=
echo %input% >> output.xls
If I can read and edit the content of a file with different extensions containing text, can't I, for exemple, edit a .xlsm file containing macros just with DOS? Maybe I can't directly interact with the macros, but there's a way to write them?

Re: BATCH interactions with opened .exe

Posted: 17 Mar 2019 04:54
by aGerman
Most of the commands can only handle plain text. They see what you would see if you open a file in a text editor. If you open a .xlsm file in a text editor you won't recognize anything of the content you see if you opened it in Excel. So again the answer is no.

Steffen

Re: BATCH interactions with opened .exe

Posted: 17 Mar 2019 11:44
by ShadowThief
Technically yes, since xlsx/xlsm/xls* files are nothing more than an archive of XML files, but the way to do it is super convoluted since you would have to extract the files, update the XML, and repack the files all using pure batch.

It can be done, but you really, really, really don't want to do this.

Re: BATCH interactions with opened .exe

Posted: 17 Mar 2019 11:56
by Mado91
Got it, thanks everyone!
anyway, even if I really, really, really wanted to do it, I wouldn't know how :lol: