Results 1 to 6 of 6
  1. #1
    broecher is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Sep 2010
    Posts
    38

    run a windodws command from macro

    When scrolling through the possible actions in the macro builder, I see a few items that say run or command or something like that. Is there an action thatt will run a command in the windows command prompt?

    I want to export a lot of csv files that then have to be processed by a python program (not written by me obviously). I currently open a cmd window and navigate to the folder and type myprogram.py f1.csv and it does its magic.



    Since I am using a macro to export a lot of these, it would be nice if I could just add another action that makes the python run also.

    Is this type of thing possible? Maybe I need to convert to vba and there is a simple way to do this there???

    Thanks in advance!

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    as far as I know, you need VBA for this. you can use it in a macro with the RUNCODE command. This requires either piping or text file streaming to manipulate DOS through VBA. I wrote a FAQ on how to do this.

    This page shows how you can use FTP file transfer through VBA: http://www.ajenterprisesonline.com/f...read.php?tid=7

    I'm not sure if you can actually substitute "cmd" in for "ftp" or any derivation of it. I've never tried. Might be worth a shot though.

  3. #3
    broecher is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Sep 2010
    Posts
    38

    Cool

    thanks for steering me in the right direction. It looks like what I want to do could be done without the text file possibly??? If I just had a module with a line that looks something like this:

    shell "cmd.exe /C myprogram.py c:/path/f1.csv", vbNormalNoFocus

    I can't test anything until I go to work tomorrow...

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by broecher View Post
    thanks for steering me in the right direction. It looks like what I want to do could be done without the text file possibly??? If I just had a module with a line that looks something like this:

    shell "cmd.exe /C myprogram.py c:/path/f1.csv", vbNormalNoFocus

    I can't test anything until I go to work tomorrow...
    I don't remember finding anything that ever worked with more than one command line in DOS. There is a bunch of code out there to open DOS and run one line, but that's very limited. As an alternative though (if you have more than one line to run), you could stream a txt and rename it as a batch file, then shell it...?

    Code:
    Dim fs, oFile
    
        Set fs = CreateObject("Scripting.FileSystemObject")
           
       Set oFile = fs.createtextfile("c:\txtCommandLines.txt", True)
    
       oFile.writeline "dir" 'what do we have in this dir?
       oFile.writeline "chdir.." 'lets go back
       oFile.writeline "dir" 'whats in this one?
       oFile.Close
    
       Name "c:\txtCommandLines.txt" As "c:\txtCommandLines.bat"
       
       shell("c:\txtCommandLines.bat", vbHide)
    
        Set fs = Nothing
        Set oFile = Nothing
    that's the only way I can see that you can execute multiple cmd's in the prompt. there just isn't any examples out there.

  5. #5
    broecher is offline Advanced Beginner
    Windows XP Access 2000
    Join Date
    Sep 2010
    Posts
    38
    oh, there is a 1 line limitation.... I understand now. that looks really useful! Can't wait to give it a try.

    Thanks again

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    if it's one line, this article is great: http://www.vbaexpress.com/kb/getarticle.php?kb_id=971

    good luck!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  2. Need help with macro
    By abc123 in forum Programming
    Replies: 6
    Last Post: 06-13-2010, 12:34 AM
  3. MACRO help please
    By DianeG in forum Forms
    Replies: 2
    Last Post: 04-20-2010, 07:19 AM
  4. Get Function to run as a macro
    By randolphoralph in forum Programming
    Replies: 11
    Last Post: 01-24-2010, 12:30 AM
  5. error in macro
    By nawaray in forum Access
    Replies: 0
    Last Post: 02-10-2009, 12:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums