+ Reply to Thread
Results 1 to 2 of 2

Problem using shell to call batch file or cmd prompt

  1. #1
    Registered User
    Join Date
    11-18-2011
    Location
    Luray, Va
    MS-Off Ver
    Excel 2007
    Posts
    9

    Problem using shell to call batch file or cmd prompt

    I'm working on my first VBA project that requires 12 fields to be manually input of which one field is a file path. I need this path for multiple reasons, but the one reason I'm having a problem with is using the location of the path in conjunction with calling a bat file or executing a cmd prompt that is at that path.

    Path Location, minus file name:
    Please Login or Register  to view this content.
    Actual Path found in B18:
    C:\Users\Nick\Desktop\Submission Tool\Test Files

    File attempting to execute:
    CopyFileNames.bat

    I can manually put all of this together and get what I want by using:
    Please Login or Register  to view this content.
    The problem is, every time this will be used, a different path will be used, but the same batch file name will be used. So, rather than having to manually input the file path every time, is there a way to replace "C:\Users\Nick\Desktop\Submission Tool\Test Files" with the cell reference of the path listed above? I've tried different methods of this but I cannot seem to get it.

    It would be even better if I could just use the cmd prompt found within the batch and run it directly from vba; the prompt I'm running is as follows:
    Please Login or Register  to view this content.
    How can I put that cmd into VBA? I tried different versions of this with no success:
    Please Login or Register  to view this content.
    Notice that the path is the same as the path shown in B18 above. It would be great if that path would be dependent on the cell referenced above.

    Thanks in advance!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Problem using shell to call batch file or cmd prompt

    Hello nickf829,

    When using the Shell command in VBA, if the argument string requires quotes be included in the command line then those quotes must be escaped with a double quote. I have done this for you below...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ 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