+ Reply to Thread
Results 1 to 14 of 14

Run Excel macro from Win 10 Run box or command prompt?

  1. #1
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    533

    Run Excel macro from Win 10 Run box or command prompt?

    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

  2. #2
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Run Excel macro from Win 10 Run box or command prompt?

    You don't
    https://support.office.com/en-us/art...0EAABAAA=Excel

  3. #3
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    533

    Re: Run Excel macro from Win 10 Run box or command prompt?

    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.

  4. #4
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Run Excel macro from Win 10 Run box or command prompt?

    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;

    Please Login or Register  to view this content.
    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"

    .
    Last edited by Haluk; 01-26-2020 at 02:56 PM.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: Run Excel macro from Win 10 Run box or command prompt?

    Quote Originally Posted by terrypin View Post
    ... how can I add parameters so that it will then run a specific macro ... ?
    Maybe use the vbs script (you can also run this vbs from a bat file).

  6. #6
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    533

    Re: Run Excel macro from Win 10 Run box or command prompt?

    Excellent, thanks Haluk! That works exactly as you describe.

  7. #7
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    533

    Re: Run Excel macro from Win 10 Run box or command prompt?

    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?

  8. #8
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Run Excel macro from Win 10 Run box or command prompt?

    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.

    Please Login or Register  to view this content.
    3) Whenever you double-click the "Starter.vbs" file, the related Xlsm file will be opened and the macro, named "myMacro" will run.

    .
    Last edited by Haluk; 01-27-2020 at 07:16 AM.

  9. #9
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: Run Excel macro from Win 10 Run box or command prompt?

    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".

  10. #10
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: Run Excel macro from Win 10 Run box or command prompt?

    However VBS is not answer for first request
    Run Excel macro from Win 10 Run box or command prompt?

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: 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.

  12. #12
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    533

    Re: Run Excel macro from Win 10 Run box or command prompt?

    Thanks Haluk, I appreciate that step-by-step explanation and will try that script alternative shortly.

  13. #13
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    533

    Re: Run Excel macro from Win 10 Run box or command prompt?

    Thanks Arkadi, I'll try that too.

  14. #14
    Registered User
    Join Date
    09-15-2019
    Location
    Gurgaon, India
    MS-Off Ver
    2003 2007 2010
    Posts
    8

    Re: Run Excel macro from Win 10 Run box or command prompt?

    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
    Attached Files Attached Files
    Last edited by DevelopmentTest; 01-28-2020 at 08:18 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need Macro to open command prompt and use some series of commands
    By balajinatarajan in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-21-2016, 03:39 AM
  2. [SOLVED] run macro from command prompt
    By uniks in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-29-2015, 01:16 AM
  3. Open Command Prompt Through Excel
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2014, 07:27 PM
  4. Command Prompt through Excel
    By Sniper in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2012, 07:07 AM
  5. Send Excel cell text to command prompt
    By miteshpanchal2006 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2012, 11:26 AM
  6. Command Prompt = Crashed Macro
    By jkelly228 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2011, 11:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1