Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Aug 2013
    Posts
    45
    Thanks
    11
    Thanked 0 Times in 0 Posts

    ,Run batch file from VBA

    Hello,

    Is this possible.

    I have a batch file located at c:\merge.bat and I want to browse to a particular directory, sub folders and run that batch script.
    The batch file only merge the text files available in sub folder.
    Last edited by foncesa; 2013-09-12 at 02:04.

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    How about something like:

    Code:
    Dim RetVal
    RetVal = Shell("c:\merge.bat", 1)
    Steve

  3. #3
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,186
    Thanks
    47
    Thanked 983 Times in 913 Posts
    If you want the batch file to work in a particular directory you need to pass the directory as a parameter, then use %* in the batch file to collect the directory name.

    Code:
    Dim RetVal
    RetVal = Shell("c:\merge.bat C:\My Directory", 1)
    Code:
    cd /d "%*"
    Copy file1+file2 file3
    cheers, Paul

Posting Permissions

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