+ Reply to Thread
Results 1 to 5 of 5

can excel write a batch file run it and import the results

  1. #1
    Forum Contributor
    Join Date
    12-24-2014
    Location
    little ole England
    MS-Off Ver
    2013
    Posts
    116

    can excel write a batch file run it and import the results

    ok this one has me scratching my head as to is this even possible with excel / vba

    been trying to create a file listing spreadsheet ( asked lots of questions here)

    working version basically works but has some limitations and after feedback from others its been shared with

    using the FSO (file system object) within VBA prevents reading of the route directory..

    so as to the question

    i can create a very simple cmd prompt routine that will read the directory and copy the file listing to a TXT file

    this text file has predefined layout based on the cmd prompt instructions.

    what i want to know and maybe get help to do is..

    if i was to put up a message box to ask for a folder (or if possible put up the FSO file selection box) and use the return

    then to write a small batch file with the cmd text to create the directory list from this folder as text file (either in the folder or a temp location)

    to read this file into excel and strip out the required info into a new sheet with the directory name


    i have attached the current working version of the workbook and a copy of the .bat batch file with the cmd code to create a filelisting.txt file (rename this file to "File Listing.bat" put this file in a folder and double click it it will run cmd prompt create file and close)

    i am wanting to know if this would be possible to do within excel so that the user would see it as a seemless operation ..

    for my own benefit the existing workbook does sub-directories ok and i could import the filelisting.txt manually

    and i never presume to know what excel can and can't do since joining this forum i am surprised daily one what can be done

    Thanks for reading and for any comments

    in the code box below is the code for the batch file for those that dislike grabbing unknown files

    Please Login or Register  to view this content.
    Attached Files Attached Files
    ◄Ŧя?μвŁ?►
    By Name & By Nature

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: can excel write a batch file run it and import the results

    Hi Trouble,

    I did not look at your files, however the following file does almost exactly what you want (slightly different dir run string). It is almost identical to the file from http://www.excelforum.com/excel-prog...h-results.html

    The only differences are the new file should run with Win64, but has not been tested with Win64 (API declarations updated).

    Lewis

    User feedback indicates that the files does run with Win64.
    Last edited by LJMetzger; 01-10-2015 at 10:39 AM. Reason: Added Win64 success note

  3. #3
    Forum Contributor
    Join Date
    12-24-2014
    Location
    little ole England
    MS-Off Ver
    2013
    Posts
    116

    Re: can excel write a batch file run it and import the results

    Quote Originally Posted by LJMetzger View Post
    Lewis
    after a little orientation yes it works on Excel 2013 64bit

    and wow that must of taken some time to put together, i had a quick look at code and you put plenty of comments so thanks for that.

    although i quickly closed it and thought about filling a pot with coffee before returning to look again

    plenty of experimenting for me to get stuck into with this and already learned a couple of things just looking

    Thanks again

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: can excel write a batch file run it and import the results

    Thanks for the kind words and the rep points.

    One thing I forgot to mention in the previous post. When running cmd.exe to run the batch file, the batch file runs in parallel with Excel. In order to sync the two parallel processes, I had the batch file create a temporary file (contents don't matter) after the 'dir' command completed. When Excel sees that the temporary file exists, Excel knows that the 'dir' command has completed.

    Thanks for the 64 bit feedback.

    Lewis

  5. #5
    Forum Contributor
    Join Date
    12-24-2014
    Location
    little ole England
    MS-Off Ver
    2013
    Posts
    116

    Re: can excel write a batch file run it and import the results

    yeah i see the temp file with date and time thought that was a clever idea

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How can I write a macro to import multiple text file iinto the same excel worksheet
    By pvimalmec in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2013, 04:11 PM
  2. Batch import and collect results in one worksheet
    By microscope in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2013, 03:16 PM
  3. Replies: 0
    Last Post: 02-08-2012, 03:55 PM
  4. [SOLVED] Would Like to Automate Batch File Creation and Text FIle Import
    By socrtwo in forum Excel General
    Replies: 2
    Last Post: 08-18-2006, 11:00 AM
  5. import batch file to excel
    By TxRaistlin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2005, 02:06 PM

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