+ Reply to Thread
Results 1 to 9 of 9

Using macro to enter variables to Shell Command

  1. #1
    Registered User
    Join Date
    10-09-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Using macro to enter variables to Shell Command

    Hi,

    I want to run a Shell command to open lots of files.

    I can get the basic command working, but I want to open a lot of different files and am seeing if there is a way to save time by having a variable input, rather than having 1000 different shell lines with IF statements.

    So...

    Instead of

    Please Login or Register  to view this content.
    If possible I want to generate 3 variables based on cells A1, A2 and A3, and have one shell command.

    So, let
    A1 = documents
    A2 = tester
    A3 = example1.txt

    The command line would now be:

    Please Login or Register  to view this content.
    and would open files from different directories based on inputs.

    Is there any way to do this, or, as I imagine, the code must be explicit as it just dumps whatever you write into dos.

    If thats the case, I thought a work around might be to enter

    Please Login or Register  to view this content.
    Into, say, B1, and then try and execute the formula in B1.

    Can this be done?

    Im still pretty new to VBA, so Im sorry if this is an obvious problem, or obviously impossible to solve.

    Any help appreciated.

    Thanks,
    Last edited by Padre; 10-12-2009 at 04:19 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using macro to enter variables to Shell Command

    Perhaps something like:
    Please Login or Register  to view this content.
    I would think the more normal way to enter text into 3 cells for sequential evaluation would be A1, B1 and C1, then the next file would be described in A2, B2 and C2, then A3, B3, and C3....etc. You could express ALL of those file instructions with a FOR/NEXT Loop, like so:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    10-09-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Using macro to enter variables to Shell Command

    Thanks for your help.

    I will try it tonight and let you know if it works

    Edit - I have just tried it at work on a basic sheet and it seems to work on a basic example.

    Will let you know how it works with my full sheet at home.

    Actually I should have specified, I want it to work with relative references. Hopefully it still will, but if anyone has any ideas.

    I.e. work with current cell, current cell down 1, and current cell down 2 - NB not all cells are in columns A and B so cant use your second iterative approach

    Another Edit -

    I made a work around by using your code, but inserting the following beforehand:

    Please Login or Register  to view this content.
    This copies the selected cell and the 2 below it to cell A1 thru 3 and then runs your shell cmd on cells 1 thru 3.

    Im all ears if there is a more elegant solution.

    Last Edit -
    Apologies for all the edits, Im probably being a little over eager.

    My work around works, but I would like it to return back to the cell it copied from, which it currently does not, and I have no idea how to get it to work out which cell it was in.

    Any ideas much appreciated, either using my work around with an idea for returning to teh initial cell, or a new approach using relative references in the "shell" line.
    Last edited by Padre; 10-12-2009 at 01:00 PM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using macro to enter variables to Shell Command

    This is such a confusing way to try and help. How about you upload a workbook with a complete set of sample data demonstrating all the hurdles, and perhaps mockup a sheet with your desired results so we can see the finish line clearly. That will speed this process up greatly.

  5. #5
    Registered User
    Join Date
    10-09-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Using macro to enter variables to Shell Command

    Sure thing.

    You are quite right - I appreciate your help.

    Attached is an example I made up. The original is bigger than the allowable limit.

    I hope it makes things clearer.

    Let me know if you have more questions and I will reply as soon as possible. Thanks again.
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using macro to enter variables to Shell Command

    Not sure I understand this workbook fully, but maybe this...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-09-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Using macro to enter variables to Shell Command

    No, you understand perfectly. Thats great thanks.

    Now I just need to work out how to extract text from shapes....

    Thanks for your time and effort. Much appreciated.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Using macro to enter variables to Shell Command

    You're going to HAVE to create individualized macros for that. Spotting specific buttons is a more direct, and it's one of those rare things you have to actually select the shape to be able to analyze the text, at least I can't seem to do it without selecting it first.

    For Page 1:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-09-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Using macro to enter variables to Shell Command

    Yes I did some digging on the net and with some modifications and experimentation I came up with:

    Please Login or Register  to view this content.
    This opens c drive\ folder "textbox1"\folder"textbox2"\"textbox3.txt" (I renamed rounded rectangle x, to textbox1,2,3)

    I think you may be right in that its not possible to select textboxA where A =(some formula)

    But I'll play around some more.
    Last edited by Padre; 10-12-2009 at 05:09 PM.

+ 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