We have have a Windows Task Scheduler job that runs an Excel xlsm file with some command line arguments as below:
Program/script:
"C:\Program Files (x86)\Microsoft Office\Office15\EXCEL.EXE"
Add arguments (optional):
"C:\File\Path\MyMacroEnabledFile.xlsm" /e/Arg1,Arg2
We would like to add a third argument with today's date, which would display in Task Manager something like the following:
"C:\File\Path\MyMacroEnabledFile.xlsm" /e/Arg1,Arg2,03-30-2024
The reason for that requirement is that the job sometimes hiccups and we have a demand job that spins through WMI processes and terminates running Excel instances based on checking the command line. It would be really helpful to see the date in the Task Manager Command Line column.
When you google Excel Command Line Arguments there are lots of examples for all kinds of things, but I can't find one that speaks to a Date command line argument. I have tried:
"C:\File\Path\MyMacroEnabledFile.xlsm" /e/Arg1,Arg2,%date
"C:\File\Path\MyMacroEnabledFile.xlsm" /e/Arg1,Arg2,%date%
"C:\File\Path\MyMacroEnabledFile.xlsm" /e/Arg1,Arg2,%Now
"C:\File\Path\MyMacroEnabledFile.xlsm" /e/Arg1,Arg2,%Now%
Bifore editing I placed a piece of code able to extract arguments and place them in a sheet of the handled workbook...
Now, I think the previous solution can be used to also answer the question, as it is formulated...
a. Please, insert a standard module, name it "CmdLineExtractString", and copy the next code inside it:
b. Insert the next code (auto Open event) inside
ThisWorbookcode module:The arguments line in Task scheduler must look as:
As I suggested in one of my comments, a suitable way can be to programmatically change the existing task arguments. Please, see how a VBScript able to do it must look:
Please, send some feedback after testing it.