+ Reply to Thread
Results 1 to 2 of 2

Can you pass parameters from a batch file to a macro?

  1. #1
    Registered User
    Join Date
    12-14-2012
    Location
    Cleveland, OH
    MS-Off Ver
    Excel 2007
    Posts
    1

    Can you pass parameters from a batch file to a macro?

    I have a a batch file that runs a couple macros. I pasted the syntax of what I have in the file below. This works to start Excel and run the macros, but my question is, is there a way I can pass parameters to the macros I am running? I want to be able to set them in the file that runs for the macros, and not have to have any users manually input the values.

    START "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" "c:\Macros\My Macro 1.xls"
    START "C:\Program Files\Microsoft Office\OFFICE11\excel.exe" "c:\Macros\My Macro 2.xls"

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Can you pass parameters from a batch file to a macro?

    The answer is yes, using environment variables defined in the .bat file, which are read by the VBA Environ function in the workbook macro which is called from the .xls Workbook_Open event procedure.

    However, a more flexible way is by using a VBScript file, for example Test.vbs:
    Please Login or Register  to view this content.
    And in a standard module in My Macro 1.xls:
    Please Login or Register  to view this content.
    Post responsibly. Search for excelforum.com

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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