+ Reply to Thread
Results 1 to 4 of 4

shell to open external bat file

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    11

    Question shell to open external bat file

    Dear all,

    i was trying to run a bat file from excel macro using shell()
    while i was able to find and run bat file, the bat file thinks it is in Libraries\Documents, instead of the folder the bat file is actually in, is there anyway to fix this?


    this is my macro
    'Location = Range("A8") + "\asdf.bat"
    'task = Shell(Location, 1)


    thanks in advance
    Best regard

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,620

    Re: shell to open external bat file

    Put a line at the top of the batfile to change to the desired directory:

    cd C:\WINDOWS\desired folder...
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    01-22-2013
    Location
    United States
    MS-Off Ver
    Excel 2013
    Posts
    11

    Re: shell to open external bat file

    thank you for replying, but i m afraid cd wont fix the problem because the location the batfile uses is not always the same, it is based of the value in cell A8. which is the current location of the bat file

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,620

    Re: shell to open external bat file

    Are you saying the the batfile itself is changing locations? Can you can edit the batfile to take parameters from the command line?
    For instance use %1 to capture the command line:

    Location = Range("A8") + "\asdf.bat " & Location
    task = Shell(Location, 1)

    Then asdf.bat would read Location into parameter variable %1
    and cd %1 would change to Location
    Last edited by protonLeah; 04-07-2013 at 12:45 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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