+ Reply to Thread
Results 1 to 5 of 5

Running commands in and reading from the command line - possible?

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    Calgary
    MS-Off Ver
    Excel 2007-2010
    Posts
    25

    Running commands in and reading from the command line - possible?

    So let's start with a giant pile of files that need to be renamed that have unpredictable filenames and file extensions.

    Let's say I can pull a report in excel format out of the system that generated those files. It will tell me the (unique) first five characters of the unpredictable filename and includes some other data that I'm putting in the filename to make it human-readable.

    I can, and already do, use a series of vlookups and concatenate functions to generate command line "ren" commands to get sensible filenames. (e.g. ="ren """&A1&"."&B1&""" """&A1&" - "&C1&" - "&D1&"."&B1&"""" yields a value of ren "asdfg.doc" "asdfg - file #10 - the quick brown fox.doc") which I then copy back into the command line. But I'd like to automate it further if possible.

    Problem #1: Can I open a command line at the location of the active workbook, cd into a subdirectory, run a dir /b, and feed the results back into column A of the active workbook?
    Problem #2: Can I automatically send the previously discussed ren commands back to the command line?

    Thanks in advance

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

    Re: Running commands in and reading from the command line - possible?

    Hi Shanyn,

    See the file associated with post #2 in the following thread. It creates a list of file using the dir /b command and can retrieve the results in a separate Excel Sheet. http://www.excelforum.com/excel-prog...h-results.html

    Lewis

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Running commands in and reading from the command line - possible?

    You can use VBA to rename files using the Name statement.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    06-11-2012
    Location
    Calgary
    MS-Off Ver
    Excel 2007-2010
    Posts
    25

    Re: Running commands in and reading from the command line - possible?

    Thanks very mcuh to both of you. These look like they will solve my problems brilliantly.

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

    Re: Running commands in and reading from the command line - possible?

    Hi Shanyn,

    See the following workbook which contains the code that follows this text. It simplifies the code in the link I provided above so it should be easier for you to follow the code. See Sheet 'Annotated' and the code module 'modAnnotated'.

    Note that some Utility routines are not listed below, but are in the attached file.

    Lewis

    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 08-30-2013, 04:56 PM
  2. VBA to command prompt - sending multiple commands to same line?
    By JP Romano in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2012, 10:42 AM
  3. [SOLVED] Running command line "aplication"
    By dim in forum Excel General
    Replies: 0
    Last Post: 10-14-2005, 06:05 AM
  4. Running Macros from Command line
    By DrukeEr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-26-2005, 01:05 PM
  5. running unix commands using vba "shell" command on mac OS X
    By fakeleft in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-09-2005, 06:08 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