Results 1 to 9 of 9
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Start Excel from command prompt (2002)

    Can you not put your code into the Workbook_Open event of an Excel file? Something like: <pre>Private Sub Workbook_Open()
    [your routine name here]
    End Sub</pre>

    HTH
    Gre

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Start Excel from command prompt (2002)

    Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>

    I want to start excel from the command prompt, opening an .xls file and starting a macro.

    Start Excel opening an .xls file is no problem: Excel.exe C:AO-LL.xls, that works.
    I found in the knowledge base an article about the available switches: http://support.microsoft.com/?kbid=211481
    The article doesn't say anything about starting macro's.
    Does anybody know what to add to the commandline to start a macro?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Start Excel from command prompt (2002)

    Unlike Word, Excel has no command line option to start a macro. The workaround suggested by <!profile=unkamunka>unkamunka<!/profile> is the one generally recommended.

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Start Excel from command prompt (2002)

    Thanks for the quick reply.
    The work-around is not possible in this case.
    I do not want to run the macro when the excel workbook is opened.
    I want to save one of the sheets as a csv file in a batch proces just before processing the csv file.
    Knowing about the possibility to start Word from the command prompt running a macro I assumed the same being possible with Excel.

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Start Excel from command prompt (2002)

    Would it be possible to have the Excel code open the target file, process it into the CSV file and then either close the workbook containing the code or close that instance of Excel? HTH
    Gre

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Start Excel from command prompt (2002)

    No, I do not want to have any user actions, it is running in an SQL Server 2000 DTS batch proces.
    I am trying to put it into a VB script now.
    The script has to open the Excelsheet, to save one of the sheets as a csv file and close excel again.
    It doesn't work yet......

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Start Excel from command prompt (2002)

    <img src=/S/confused.gif border=0 alt=confused width=15 height=20>Script runs Excel.exe C:RunMyRoutine.xls. RunMyRoutine.xls opens target file, saves sheet in CSV format and exits with Application.Quit.
    Gre

  8. #8
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Start Excel from command prompt (2002)

    There are two approaches that I can think of:

    1- Put your code in the Open event routine of the workbook in question. Dream up your own command line switch. Run Excel with the filename and your switch. In the Open event routine, have your code check the command line for your switch, and if it is not there do nothing. If it is there, create the .CSV file and exit Excel using Application.Quit.

    2- Put your code into the Open even routine of another workbook. Run Excel specifing that workbook as the one to open. In the Open event routine, open the real workbook, create the .CSV file, and then exit Excel using Aplication.Quit.
    Legare Coleman

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Start Excel from command prompt (2002)

    See if this page gives you some ideas.

    Edited: somehow couldn't get the url to work.

    Search Google groups, using these keywords:

    excel command line read vba

    Click the first entry.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

Posting Permissions

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