+ Reply to Thread
Results 1 to 2 of 2

run cmd commands via Macro in excel

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    Londo, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    run cmd commands via Macro in excel

    well im trying to make a macro that gets all the inputs and runs a command.

    the command that i have to run have two parts
    first i have to go to a folder with cmd, and then i have to run a command (string with all the inputs, the program i want to use via CMD is Sarmanalyzer).

    i alread see how to open a cmd but i dont know how to write in it, the other option i read is to write a bat file with the inputs and then run it but i dont know nothing about creating bat files.

    well if you could give me information about this two types of solution (or other solution for this) please help me.

    thanks for all!


    another thing i want to do is import the output of that command (CSV) in another sheet, is there a way to import it via VB?

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: run cmd commands via Macro in excel

    Hi

    Have a look at this.

    Sub shell_commands()
    'code by xlbiznes
    ' cmd /k keeps the window open and cmd /c closes the window
    'seperate one command from the other by using & and use && to run the command only if the previous one was succesful
    Dim my_cmd
    my_cmd = Shell("cmd /k cd c:\my_data & dir > my_data.txt")
    
    End Sub
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

+ 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