+ Reply to Thread
Results 1 to 3 of 3

getting vba shell command to execute batch and save output to a file

  1. #1
    Mad Scientist Jr
    Guest

    getting vba shell command to execute batch and save output to a file

    I have a batch file I would like to execute from an Excel macro, and
    have the output be piped to a file. For this test I created a file
    "dir.bat" in the same folder as "Book1.xls", the file contains one
    line, "dir /b /o"

    >From the command prompt, if I run it like so


    dir.bat > dir.txt

    it successfully saves the directory listing to "dir.txt".

    However it doesn't seem to be working from the Excel macro:

    Sub ShellTest()
    Shell ThisWorkbook.Path & "\dir.bat > dir.txt"
    End Sub

    I get no error messages, and dir.txt gets created, but it is empty.

    Can anyone see anything wrong?

    Much appreciated...


  2. #2
    Tom Ogilvy
    Guest

    RE: getting vba shell command to execute batch and save output to a fi

    why not change the line in the bat file to

    "dir /b /o > dir.txt"

    --
    Regards,
    Tom Ogilvy


    "Mad Scientist Jr" wrote:

    > I have a batch file I would like to execute from an Excel macro, and
    > have the output be piped to a file. For this test I created a file
    > "dir.bat" in the same folder as "Book1.xls", the file contains one
    > line, "dir /b /o"
    >
    > >From the command prompt, if I run it like so

    >
    > dir.bat > dir.txt
    >
    > it successfully saves the directory listing to "dir.txt".
    >
    > However it doesn't seem to be working from the Excel macro:
    >
    > Sub ShellTest()
    > Shell ThisWorkbook.Path & "\dir.bat > dir.txt"
    > End Sub
    >
    > I get no error messages, and dir.txt gets created, but it is empty.
    >
    > Can anyone see anything wrong?
    >
    > Much appreciated...
    >
    >


  3. #3
    Mad Scientist Jr
    Guest

    Re: getting vba shell command to execute batch and save output to a fi

    "Why didn't I think of that?!"
    Sounds like a good idea, let me try that, thanks!

    Tom Ogilvy wrote:
    > why not change the line in the bat file to
    >
    > "dir /b /o > dir.txt"
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Mad Scientist Jr" wrote:
    >
    > > I have a batch file I would like to execute from an Excel macro, and
    > > have the output be piped to a file. For this test I created a file
    > > "dir.bat" in the same folder as "Book1.xls", the file contains one
    > > line, "dir /b /o"
    > >
    > > >From the command prompt, if I run it like so

    > >
    > > dir.bat > dir.txt
    > >
    > > it successfully saves the directory listing to "dir.txt".
    > >
    > > However it doesn't seem to be working from the Excel macro:
    > >
    > > Sub ShellTest()
    > > Shell ThisWorkbook.Path & "\dir.bat > dir.txt"
    > > End Sub
    > >
    > > I get no error messages, and dir.txt gets created, but it is empty.
    > >
    > > Can anyone see anything wrong?
    > >
    > > Much appreciated...
    > >
    > >



+ 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