How to run a excel macro from commandline or thru .bat batch
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: How to run a excel macro from commandline or thru .bat batch

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Hi people,

    Is there a way of running excel macro from command line or using .bat ( batch file or operating system script file ).

    I want to write a batch file which converts text file into excel file with certain columns protected and store it in new file name.

    Can it be done from dos/windows/unix command prompt without invoking MS-Excel by double clicking?

    Thanks in advance,

    -N

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Reply, I don't believe this is possible. It is possible to run a commandline instruction or a batch file from Excel if that's any help to you.

  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default


    I need excel macro to be executed from command line. ( not command line from excel ).

    Will this work?!
    i)save a text file with .xls extension
    ii) write a macro, put it as part of file which should run automatically when user opens the file.

    ideas welcome.. thanks and appreciate your suggestions

  4. #4
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Running the Excel sheet from the command line and starting the macros from the "Worksheet_Open" event would work, but with one snag.

    You will be prompted to enable or disable macros when the workbook opens. There are two known ways to bypass this.

    1. Lower the security of Excel on the Tools|Macros|Security menu. (This is not recommended by anyone as your susceptible to malicious macros)

    2. Become a "trusted source" for the users using Digital Signatures. I haven't used these and you'll need to check XL help or microsoft.com for how to use this. (people on this board are wary of digital signatures as well)

    HTH

  5. #5
    Board Regular
    Join Date
    Aug 2002
    Posts
    91
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    I've been wondering about this too. My sheet has to be able to be opened without running the macro, too, though.

    One trick might be to have the batch file create a dummy file on c: root, then have the Excel function check if that file exists. If it does, then it is meant to auto execute that particular function (or perhaps one of many depending on the name of the file). Then the batch file deletes the file after excel.exe exits.

    Whether the function modifies the spreadsheet requiring a save, and how to automate the save I don't know (yet).

    Any more clever ideas on how to do this?

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com