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
BATCH interactions with opened .exe
Moderator: DosItHelp
Re: BATCH interactions with opened .exe
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
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
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:
or even
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?
Code: Select all
set /P input=
echo %input% >> output.txt
Code: Select all
set /P input=
echo %input% >> output.xls
Re: BATCH interactions with opened .exe
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
Steffen
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: BATCH interactions with opened .exe
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.
It can be done, but you really, really, really don't want to do this.
Re: BATCH interactions with opened .exe
Got it, thanks everyone!
anyway, even if I really, really, really wanted to do it, I wouldn't know how
anyway, even if I really, really, really wanted to do it, I wouldn't know how