I can open an Excel workbook from the Run box with
C:\Users\terry\Walks\WalkIndex.xlsm
But how can I add parameters so that it will then run a specific macro please?
I can open an Excel workbook from the Run box with
C:\Users\terry\Walks\WalkIndex.xlsm
But how can I add parameters so that it will then run a specific macro please?
Terry, East Grinstead, UK
Excel 365, Win 10 Pro, i7 PC, 4.0 GHz
Thanks for the link. The opening paragraph of that article includes this promising sentence:
"Or, you want to customize the process even more by loading an add-in or running a macro upon startup. You can add options like this by using subcommands called command-line switches to an Office app's startup command"
(My highlighting.)
But, as you imply, I can find no subsequent info on how to run a macro on startup. Is this only possible by including that macro in \XLSTART?
Last edited by terrypin; 01-26-2020 at 01:46 PM.
As per your "bold" statement in your message #3, you can do it in this way;
Place a Auto_Open procedure in your "WalkIndex.xlsm" file and call your desired macro from this Auto_Open procedure.
Such as;
So, when you run your command from the "Run Box", after the Excel file is opened the Auto_Open procedure will trigger the macro named "myMacro"Please Login or Register to view this content.
.
Last edited by Haluk; 01-26-2020 at 02:56 PM.
Excellent, thanks Haluk! That works exactly as you describe.
Thanks. Although Haluk's simpler solution works for me, as a VBA novice I'd like to try other methods as part of my learning. But what script do you mean?
If you wish, you can try a VBS (Visual Basic Script) like this;
1) Start your Notepad.exe and create a new text document.
2) Paste the following code into the text document and save as "Starter.vbs" and close the file.
Be sure to choose "All files" from the "Save as type" box and write "Starter.vbs" into the "File name" box.
3) Whenever you double-click the "Starter.vbs" file, the related Xlsm file will be opened and the macro, named "myMacro" will run.Please Login or Register to view this content.
.
Last edited by Haluk; 01-27-2020 at 07:16 AM.
In this particular case it will be better to use arguments (e.g. Set args = WScript.Arguments) than rigid assignments of paths and file names in vbs. The name of the xls file and the path to it is better "to include" in the bat file and call Excel from it, then you can run the xls file from the Windows Run field like a "command with parameters".
However VBS is not answer for first request
Run Excel macro from Win 10 Run box or command prompt?
It is possible to either configure a shortcut or just type a command line parameter when running an excel file. That can (with some code) then be identified. In my case, I add /e /email to the end of mine, which then allows me to have the code do something only when the /email is present. Keep in mind this example is a shortcut setup, and the "target" value on that shortcut is:
"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" "\\alpha\company\DatabaseTests\ADO Programs\ProductionPrograms\Failed_Rubber_Disposal.xlsm" /e/email
If I use the shortcut an email is sent out, and if I just open the file another way, then it does not email. You won't see the actual condition for emailing since that happens in another sub in a different module, but just like the workbook close command, it is dependent on the global variable "send_email" which is True only when the parameter is added.
The code from the module that deals with this is:
Please Login or Register to view this content.
Please help by:
Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know
There are 10 kinds of people in this world... those who understand binary, and those who don't.
Thanks Haluk, I appreciate that step-by-step explanation and will try that script alternative shortly.
Thanks Arkadi, I'll try that too.
Just quick. not sure if relevant here is..
Full explicit use Application.Run will open workbook is containing macro.
Code line will work with workbook is containing macro has open is or not is
Like
Application.Run Macro:= "'C:\Users\terry\Walks\WalkIndex.xlsm'" & "!Module1. myMacro", arg1:="myArg"
So is like in uploaded workbooks… So do this
Put workbooks in same folder
Open just is then
OpenFileRunIt.xlsm
(enable macros is to be done as well maybe )
Run this in It() sub
Sub It()
Application.Run Macro:="'" & ThisWorkbook.Path & "\" & "IsClosed.xlsm" & "'" & "!Module1.myMacro", arg1:="message2U, Tel"
End Sub
Other workbook, IsClosed.xlsm , will be opened and it Tels you a message
Test it
Last edited by DevelopmentTest; 01-28-2020 at 08:18 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks