+ Reply to Thread
Results 1 to 14 of 14

Run command in cmd.exe using the string from a particular cell

Hybrid View

  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    7

    Run command in cmd.exe using the string from a particular cell

    So basically guys I have this command string in cell E26 which gets generated by the changing values in the cells E9, E11 & E12.

    C:\software license\License.exe Evaluation 30


    All I need to do is Run this string which is in cell E26 in cmd.exe using a macro. I cannot figure out how to? I am trying different VBA's but all it doing is opening the cmd and not executing it.

    If possible please help me with two different VBA's:
    1) Running string in CMD silent mode.
    2) Running string in CMD with CMD window open.

    __________________________________

    Cell Values:-
    E9 = File path name
    E11 = Evaluation\Annual\Perpetual
    E12 = 30\365\730 (Days)

    Formula in E26 is:-
    =E9&" "&E11&" "&E12

    ---------- Post added at 10:00 AM ---------- Previous post was at 09:54 AM ----------

    Any changes which you would recommend in this?

    Sub Run.command()
         
         
        Dim Par As String
        Par = Range("E26")
        Call Shell("C:\WINDOWS\system32\cmd.exe /c " & Par, 1)
         
    End Sub
    Last edited by smasher007; 08-30-2012 at 12:08 PM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run command in cmd.exe using the string from a particular cell

    replace /c with /k if you want the window to remain open
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    08-02-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run command in cmd.exe using the string from a particular cell

    @ JosephP: Thank you for your reply.

    Unfortunately it responds with 'C:\software' is not recognized as an internal or external command, operable program or batch file.

    How can I fix this?
    Last edited by smasher007; 08-30-2012 at 12:21 PM.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run command in cmd.exe using the string from a particular cell

    are you sure that the path is correct? can you run that from a command line directly?

  5. #5
    Registered User
    Join Date
    08-02-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run command in cmd.exe using the string from a particular cell

    Actually it is not executing the entire path if there is a space in between.

    The actual path is 'C:\software license\License.exe'

    Any ideas? The thing is my software has many parameters separated by space. eg: License.exe Evaluation 30

    However, I am able to execute the entire string from the RUN box (Win + R)
    Last edited by smasher007; 08-30-2012 at 11:46 AM.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run command in cmd.exe using the string from a particular cell

    try
    Sub Run.command()
        Dim Par As String
        Par = Range("E26").value
        Call Shell("cmd.exe /c """ & Par & """", 1)
         
    End Sub

  7. #7
    Registered User
    Join Date
    08-02-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run command in cmd.exe using the string from a particular cell

    Unfortunately it responds with 'C:\software' is not recognized as an internal or external command, operable program or batch file.

    What do the extra """ & """" do?
    Last edited by Cutter; 08-30-2012 at 08:06 PM. Reason: Removed whole post quote

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run command in cmd.exe using the string from a particular cell

    they pass the program name in quotes which should avoid exactly that problem!

  9. #9
    Registered User
    Join Date
    08-02-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run command in cmd.exe using the string from a particular cell

    OK. Thanks! But it is still stopping before the space.. is there any other alternative.?

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run command in cmd.exe using the string from a particular cell

    not that I can think of. that code executes as expected in my tests using paths with spaces

  11. #11
    Registered User
    Join Date
    08-02-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run command in cmd.exe using the string from a particular cell

    Has the number of "" something to do with the number of spaces? Also is there any other way to paste this in run instead of cmd.exe?

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run command in cmd.exe using the string from a particular cell

    if you don't want cmd then just use shell
    Call Shell("""" & Par & """", 1)
    the number of quotes has nothing to do with the number of spaces

  13. #13
    Registered User
    Join Date
    08-02-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Run command in cmd.exe using the string from a particular cell

    Quote Originally Posted by JosephP View Post
    if you don't want cmd then just use shell
    Call Shell("""" & Par & """", 1)
    the number of quotes has nothing to do with the number of spaces
    The above code returned with a debug window.

    But thank you for all your replies. I removed the spaces from the program path and used your first code. The program parameters separated by a space are now working properly.

    The only problem now is that the output is now getting saved in "C:\Users\smasher007\Documents". How can I set this to a custom path or to same program directory? Any ideas?

  14. #14
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Run command in cmd.exe using the string from a particular cell

    not really-I guess it's probably a program setting or perhaps it just outputs to the current directory. try changing the current directory to another folder

+ 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